Jump to content
Sign in to follow this  

Hex to Binary (serial feedback project)

Recommended Posts


Hello Gang,

I have a question that i cant wrap my head around. I am working with a USB relay board (rs232) with AutoIT.

I have got connection and i can send instructions and receive feedback successfully so far, but i have a puzzle problem now i cant get my head around.

The board operate on strings like !00200000004 and returns _00000004. Here is the breakdown.


! = sending command

00 = usb board ID

2 = turn on relays prefix

00000004 = Hex representation of nibbles that represent the individual relays, IE this command would turn on relay number 3 and turn off 1-2&4-32 (sorry its a 32 relay board)

In the same vein the return string of 00000004 indicates all relays are off/open except number 3.

So in case the identification string isnt clear heres an explination:

each of the 8 hex characters represents a bank of 4 relays, the different hex digit that is displayed represents different relay or combinations of relays in that bank. So in the above example of 00000004 identifies relay #3 here is why.

hex 4 in binary = 0100 = which is position 3 when counting from LSB and since its 1'ed the relay is on. So another example ... string output of 0000000E would equal

hex E in binary = 1110 = which would indicate that relays #2 #3 #4 would be on.

Great - now the brain puzzle. How would i be able to algorithmlicly (i dont know what im saying here) turn the 8 digit hex string into binary (which ive already searched for and havent found) and then use find the binary posistions so i can eventually output decimal position ID.

I dont want you to write code for me or anything like that - hell no im doing this shiz from the ground up solomente but my issue is purley problem solving and maybe asking if a hex to binary function exists.

Sorry about the length of the post i felt that it was a pretty abstract identification method that needed explination to get some real help out of the forum.

Thanks all in advance!

Share this post

Link to post
Share on other sites

You might want to build a truth table. Try mapping all your possible inputs to your outputs. See if any patterns show up.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this