Hex to Bin

buddyB

Newcomer
Joined
Nov 13, 2003
Messages
10
Location
Eindhoven, NL
Dear...

I need to convert a hexadecimal code (string of 1 byte) to a binary code (string of 4 bytes).
Other possible solutions are okay too.

The help-file gives the following solution:


Code:
--------------------------------------------------------------------------------
“Function HexToBinary( ByVal HexString As String) As String”


--------------------------------------------------------------------------------



Does anyone know how to do this ?

Regards,
BuddyB
 
One solution would probably be to call a few replace methods.
Replace 0 with 0000, 1 with 0001, 2 with 0010, 3 with 0011, etc.
E with 1110, and F with 1111. :)
 
Try this:
C#:
// s is the hex string
string s = "C2";
// b will be the binary string
string b = Convert.ToString(Convert.ToInt32(s, 16), 2);

-Nerseus
 
Back
Top