Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Intermediate
Sep 7, 2002

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 binary
Console.WriteLine(Convert.ToString(11, 2))    ' => 1011
' convert to octal
Console.WriteLine(Convert.ToString(123, 8))    ' => 173
' convert to hexadecimal
Console.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.
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap