# convert binary to hexadecimal in vb



## gvp (Aug 15, 2005)

i am using vb (or vba) to read files (c-isam) containing binary data. 
Some bytes have the binary value "00", so the string functions in vb doesn't work very well.

i am looking for a 'vb' function to convert the data that i have read into a string with the hexadecimal presentation of the value. Just in the same way of that i can see the data with a hexeditor like hexedit or ultraedit.

ex : if the string contains the value : "AaB" the result must be "416142"

but if the second byte of the string contains the binary value 0 then
the result must be "410042"

I need also a function to convert the hexadecimal value back to the binary value

Seraching the internet i found solutions in other languages , but vb is the only language i know a little so i am looking for help

thanks i advance
gvp


----------



## Chicon (Jul 29, 2004)

Hi gvp,

You should use arrays in your coding.
Example : *Dim array_to_scan() as String*
Therefore, you can test the value of each item of the array.


----------



## CtrlAltDestr (Sep 29, 2004)

This does not require a function, but is built into VB.

I use VB6, and I can abbreviate numbers in hexidecimal by appending &h to the beginning.

For example... &hA + &h12 will return 28, a decimal value.

You can use the Hex() function to convert a decimal value to a hex value. For example, Hex(678) will return the string "2A6", a hexidecimal value.


----------

