How to store a string in Byte array in hex form
-
I want store a string in byte array in hex format.How can I do this. Actually I want to store an IP address like 165.8.98.76 in byte array. I am using Hex() method to convert each no. like changing 165 to its hex no. Then chnage 8 to 8. and so on. But Now how can i store this in byte array. Problem- When I convert a no. to hex.Suppose 35 in decimal to 23 in hex. and when i use BIp = StrConv(strIp, vbFromUnicode) Then it stores each digit in 1 byte. Suppose 172= AC in hex the above method store 'A' in 1 byte and 'C' in 2 byte. How can I store IP Address in Byte array. Thanks in adv.
-
I want store a string in byte array in hex format.How can I do this. Actually I want to store an IP address like 165.8.98.76 in byte array. I am using Hex() method to convert each no. like changing 165 to its hex no. Then chnage 8 to 8. and so on. But Now how can i store this in byte array. Problem- When I convert a no. to hex.Suppose 35 in decimal to 23 in hex. and when i use BIp = StrConv(strIp, vbFromUnicode) Then it stores each digit in 1 byte. Suppose 172= AC in hex the above method store 'A' in 1 byte and 'C' in 2 byte. How can I store IP Address in Byte array. Thanks in adv.
You definiately do not screw around with the Hex function to do this. Have you seen the System.Net.IpAddress class, and it's GetAddressBytes method? You might even look at its HostToMetworkOrder and NetworkToHostOrder methods, depending on what you're doing with the byte version of the address.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak