Simple Binary to Displayable Hex Conversion If you've ever needed to display a binary data for diagnostic or monitoring programs you can convert the binary data to displayable hexadecimal data with only two instructions. Over time, I've seen all kinds of techniques involving shifting bits around, lots of CLI's, OR's, etc., etc.. Here's a code snippet illustrating the technique using UNPK and TR:
In the above example, we convert a four byte binary field into an eight byte displayable hexadecimal field. Note the extra byte after the binary and displayable hexadecimal fields. I typically prefer to convert a word at a time, but you could convert any number of bytes up to 15 at one time. My recommendation is to stick to converting words (4 bytes) or double-words (8 bytes) at a time. Also note that we
only need the last sixteen bytes of the translate table, thus the " Follow this link for inverse of this example to convert displayable hexadecimal back to binary. I will continue to add tips and techniques as time permits. Please direct any
inquiries or problems regarding this web to webmaster@marcsweb.com Revision Date:
Wednesday, November 15, 2006 09:59:23 AM
|