Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a routine to write conversion from integer to binary numbers 2

Status
Not open for further replies.

stonecold

Programmer
Jan 24, 2001
1
US
I need to convert a single integer number to binary code and print the binary code out in c
 
Perhaps there is a format converter string for binaries.
For Hex it is %x

hnd
hasso55@yahoo.com

 
If by 'binary code' you mean 5 = 0101

int number = 5;
BigInteger bi = new BigInteger(new Integer(number).toString());
System.out.println( bi.toString(2));

Hope this helps
-pete
 
Ok, so now if you ever need to do this in Java you know how.

So here is how to do it in C B-)

char buf[255];
int myint = 5;
_itoa(myint, buf, 2);
/* buf now contains "101" */


Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top