I assume you mean decimal to hex…

Decimal (base 10)

Hexadecimal (base 16)

Binary (base 2)

 

Anyway, something like this might work:

 

static string DecToHex(int number)

{

    return string.Format(“{0:X}”, number);

}

 

string hex = DecToHex(108);

 

hex would equal “6C”.

 

using “{0:x}” as the format string would produce “6c”.

using “{0,4:X}” as the format string would produce “  6C” (two spaces). You could then replace all spaces to zeros like this:

 

static string DecToHex(int number)

{

    return string.Format(“0x{0,4:X}”, number).Replace(“ “, “0”);

}

 

which would produce “0x006C”.

 

I hope this helps!

 

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shawn Haigh
Sent: Thursday, November 18, 2004 10:14 AM
To: [EMAIL PROTECTED]
Subject: [Nant-users] bin 2 hex

 

Greetings,

 

Does anyone out there have a neat function to convert a binary number to its hex equivalent?

 

Ex;

 

108     to 0x006C

 

cheers

 

Shawn Haigh


 

Reply via email to