Showing posts with label Decimal. Show all posts
Showing posts with label Decimal. Show all posts

Wednesday, December 19, 2012

C# Convert Decimal to Binary and Vice Versa

Decimal to Binary conversion as below:
 
int DecimalVal = 256;
string BinaryVal = Convert.ToString(DecimalVal, 2);
Binary to Decimal conversion as below:
 
string BinaryVal = "01001101";
string DecimalVal = Convert.ToInt32(BinaryVal, 2).ToString();

C# Convert Hex to Decimal and vice versa

Convert Hex to Decimal as below;
 
int DecimalVal = Convert.ToInt32(HexVal, 16);
Convert Decimal to Hex as below;
 
string HexVal = DecimalVal .ToString("X");