Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Inbuilt decimal to binary conversion function in C++ (http://www.velocityreviews.com/forums/t283759-inbuilt-decimal-to-binary-conversion-function-in-c.html)

Raja 06-16-2004 02:00 PM

Inbuilt decimal to binary conversion function in C++
 
IS there any inbuilt decimal to binary conversion function in C++

Sharad Kala 06-16-2004 02:16 PM

Re: Inbuilt decimal to binary conversion function in C++
 

"Raja" <sharnakcl@yahoo.com> wrote in message
news:b28e2ece.0406160600.3e050459@posting.google.c om...
> 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



JKop 06-17-2004 11:10 AM

Re: Inbuilt decimal to binary conversion function in C++
 
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


All times are GMT. The time now is 11:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.