What is the easiest way to convert decimal to binary in C# ?

Status
Not open for further replies.

coolchip

Full Member level 2
Joined
Nov 17, 2003
Messages
125
Helped
1
Reputation
2
Reaction score
2
Trophy points
1,298
Activity points
1,109
base conversion in C#

what is the easiest way to convert decimal to binary in C# ?
Is there any library function to do the same ?

TIA

Cheers
 

Re: base conversion in C#

The answer to your question is: "use cast"

I never used decimal in my programs.
Instead i prefer to work with int (or Int32 ,is the same) or uint (or Uint32, is the same )
Reason: Many build in functions and operators C# works well with those types (also bit operations >> << | & are fully implemented for those tipes).

example:

int number=0x1234;
byte HighByte= (byte) (number/0x100);
byte LowByte=(byte)(number%0x100);

For decimal types, you can use same technics, but take care, after casting, you can loose data.
So a litle debuging is nedeed.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…