Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you convert a string into hexadecimal in VB.NET?

Tags:

vb.net

How do I convert a string from a textbox into hexadecimal?

I have only found ways in C#. Does VB.NET have the ability to do such a thing? If it can then I'd like to know how to convert string to hex and hex to string.

like image 354
Mark Chai Avatar asked Nov 29 '22 09:11

Mark Chai


2 Answers

Dim val As String
val = "10"
Dim hexVal As Integer
hexVal = Convert.ToInt32(val, 16) //16 specifies the base
Console.WriteLine(hexVal)

This will display 16 which is the integer equivalent of the hexadecimal string "10".

like image 163
Habib Avatar answered Dec 30 '22 09:12

Habib


You can convert an integer to a hexdecimal number easily by doing:

Convert.ToInt32(15, 16)

And to convert it back to an integer, you can do:

Integer.Parse("15f", System.Globalization.NumberStyles.HexNumber)
like image 40
Rasmus Søborg Avatar answered Dec 30 '22 08:12

Rasmus Søborg