I'm communicating with a device that requires a password to be embedded into the command using hex. The password must be 8 bytes. If the ASCII numeric password is less then 16 digits the password is padded with a F.
For example if the password is 12345 I need to be able to convert the password to 0x12 0x34 0x5F 0xFF 0xFF 0xFF 0xFF 0xFF.
What I am not sure how to do is get 0x12 from "12".
I was thinking about if I could convert 1 to 0x10 and 2 to 0x02 I could then add the two bytes together to get 0x12. However is there a way to get the 0x10 and 0x02 without having to create a hash table or is there a better approach?
Edit: To whomever was rude enough to down vote. This is a unique question I'm not looking to do simple get the hex value of 12345 where as hex it would be represented as 31 32 33 34 35. If one of the other answers in that question does cover this, this at least presents the answer to the question where the questioned is presented directly. I intend to look into the bit shifting and the answers to the linked question flew right over my head. If this site is intended to facilitate learning then we cannot have a catch all section because the answer becomes too complex to help a layman learn.