News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Problem with bin2hex

Started by MichaelW, February 06, 2007, 12:57:01 PM

Previous topic - Next topic

MichaelW

The MASM32 bin2hex procedure adds only a CR for a binary data length of 16 bytes, and only a CR starting with the position of the second line break for longer data lengths (I did not actually test lengths greater than 32). Also, the documentation specifies a minimum destination buffer length of 3 times the source length, when if you include the terminating null this is inadequate for any source length greater than 5. By the time the source length reaches 32 the required length is 3 times the source length plus 6, and would be greater if the line breaks were all CRLFs. I think a multiplier of 3.25 might be sufficient for any source length. The attachment is the test app I used.



[attachment deleted by admin]
eschew obfuscation

hutch--

Michael,

Thanks, I have a habit of using byte length * 4 with the particular algo which is safe but the documentation needs to be changed.

Quote
Comments
The output data is approximately 3 times longer than the source data as it uses 2 characters plus a space for every byte in HEX format. The destination buffer should be at least 3 times the length of the source buffer to hold the result.

It is probably worth adding that for small sizes, * 4 works fine but for a larger allocation a finer grained multiplier of 3.25 / 3.3 is more accurate.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php