• Support
  • Articles
  • Resources
  • Products

Hex rx to string

Moderator: boris

2 postsPage 1 of 1

rdm
Newbie

Posts:
9
Joined: Fri Jul 29, 2011 4:44 pm
by rdm » Tue Nov 29, 2016 11:59 pm
I set debug mode to 2 (hex) and receive a reply such as this:
82 00 00 00 2E 00 04 00 0A 00 00 00 05 30 31 32 33 34 35 36 37 38 39

I do it this way because I have a mix of printable and non-printables.
Is there a command that can convert the printable chars starting at 30 31 32 33... , to a printable string, perhaps to a logfile? Or must I create a subroutine?
Trevor
Guru

Posts:
483
Joined: Wed Jul 26, 2006 8:47 am
by Trevor » Wed Nov 30, 2016 10:34 am
Something like this (not tested) would accumulate the output into a string but you could log it or wrtite to file instead. Depends on what you want to do. It uses a dot for non-printable bytes.

Code: Select all

  1. setdebug 2
  2. output_string = ""
  3. while 1
  4.     ; wait for a hex sting representing a byte (seperated by space)
  5.     wait ' '
  6.    
  7.     ; convert hex string to byte
  8.     sprintf2 hex_str "0x%s" inputstr
  9.     str2int byte hex_str
  10.  
  11.     if byte >= $30 && byte <= $7E then
  12.         ; if printable convert byte to ASCII
  13.         code2str str byte
  14.     else
  15.         ; just add a dot if not printable
  16.         str = '.'
  17.     endif
  18.     strconcat output_string str
  19. endwhile
Display posts from previous:
Sort by:

2 postsPage 1 of 1

Users browsing this forum: No registered users
cron