Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 62 / 68

Converting between bases (binary and hexadecimal)

This lesson covers converting between bases in VB.NET, with the aim of deepening your understanding of how numbers are represented inside a computer.

Convert.ToString(number, base) converts to a string in the base you specify and Convert.ToInt32(string, base) converts back. Beyond everyday decimal, binary and hexadecimal come up constantly in computing.

The sample code converts 42 to binary with Convert.ToString(42, 2) and to hexadecimal with Convert.ToString(42, 16), then turns the binary string back into the original number with Convert.ToInt32("101010", 2).

A common early stumble is the relationship between a base and the values it uses. Hexadecimal uses a–f after 0–9, and the notation takes some adjusting to from a decimal habit.

In professional work, knowing your bases helps wherever non-decimal notation appears — hexadecimal colour codes, bit flags, memory addresses.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)