Convert a decimal value to binary, octal, or hexadecimal

Convert a decimal value to binary, octal, or hexadecimal

The ToString method of the Convert class lets you easily and quickly convert a decimal value into a string representation of that number to binary, octal, or hexadecimal base:

' convert to binaryConsole.WriteLine(Convert.ToString(11, 2))    ' => 1011' convert to octalConsole.WriteLine(Convert.ToString(123, 8))    ' => 173' convert to hexadecimalConsole.WriteLine(Convert.ToString(254, 16))    ' => fe

The ToString method is overloaded to take a Byte, a Short, an Integer, or a Long value in the first argument; the second argument can only be 2, 8, 10, or 16, else an exception will be thrown.

See also - an AI reverse image search platform

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist