Inbuilt decimal to binary conversion function in C++

S

Sharad Kala

Raja said:
IS there any inbuilt decimal to binary conversion function in C++

I think you mean to get binary representation of a given int.

cout << bistset<10>(7); // 7 in binary with 10 bits

-Sharad
 
J

JKop

Raja posted:
IS there any inbuilt decimal to binary conversion function in C++


Well... all computers store data in binary.

As such I pressume you're talking about strings, ie.


"23" -> "00010111"


Maybe something along the lines of:


#include <stdlib.h>

int main(void)
{
char binary_string[10];

unsigned short int number = 23;

itoa(number,binary_string,2);

//The 2 in the above specifies the radix, ie. the number of digits
//in the number system. For decimal, this would be 10. For, octal, 8.
//For Hexadecimal, 16. For binary, 2.

}



-JKop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,468
Latest member
Fannie44U3

Latest Threads

Top