answersLogoWhite

0

#include<iostream>

#include<string>

#include<limits>

#include<iomanip>

std::string char2bin( char c )

{

std::string result( 8, '0');

int bit = 8;

while( bit-- )

{

result[bit] += (c & 0x01);

c >>= 1;

}

return( result );

}

template<typename T>

std::string tobin( T t )

{

std::string result;

const size_t size = sizeof( T );

char* p = (char*) &t + size - 1;

unsigned int s = size;

while( s-- )

result += char2bin( *p-- );

return( result );

}

int main()

{

double d = 1.2345;

float f = 1.2345;

std::cout<<std::setprecision(std::numeric_limits<float>::digits10+1)<<d<<" (float) in binary is "<<tobin(f).c_str()<<std::endl;

std::cout<<std::setprecision(std::numeric_limits<double>::digits10+1)<<d<<" (double) in binary is "<<tobin(d).c_str()<<std::endl;

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What is the sum of the binary numbers of 1001 plus 10 in both binary and decimal?

easy, 1011. in binary of course. convert 1011 binary to decimal you get 11.


What is the answer of binary decimal plus binary?

If you want to add numbers in different bases, in this case decimal and binary, or do any other calculation that involves different bases for that matter, you have to convert all numbers to a single system first - for example, all to decimal. Then you can do the operation. It is really up to you in what base you represent the final answer. In this example, you can convert back to binary, for example.


What is 1 plus 1 plus?

2 decimal, or 10 binary.


C plus plus program that convert decimal to binary using the concept of stack?

#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; main() { int number,binary[10000],b=0; printf("Enter decimal number "); scanf("%d",&amp;number); printf("\nBinary: "); for(;number;number/=2,b++) binary[b]=number%2; for(b--;b&gt;-1;b--) printf("%d ",binary[b]); }


What does binary 100000001 plus binary 11010111 equal?

111011000 (decimal 472). The sum is 257+215.


What is 111 plus 11 in binary?

0111 = decimal 7 0011 = decimal 3 ____ 1010 = decimal 10 ____


What is the sum of 10 plus 1?

In binary it's the equivalent of decimal 3.


What is 100 plus 101 equals?

201 in decimal1001 in binary9 in binary translated to decimal


What is the binary numbers for 10111 plus 101111?

1000110. In decimal, the sum is 23+47=70.


111111 to the base2 plus 10001 to the base2?

To add these two binary numbers, we can first convert them to decimal. 111111 in base 2 is equal to 63 in base 10, and 10001 in base 2 is equal to 17 in base 10. Adding these two decimal numbers gives us 63 + 17 = 80 in base 10. Finally, we convert 80 back to binary to get the final answer, which is 1010000 in base 2.


What does the binary addition of 01001101 plus 00100010 equal in decimal form?

The first number (01001101) is equal to the decimal number 77. The second number (00100010) is equal to the decimal number 34. If you add the two together in decimal, you get 111. Expressed as a binary number, 111 is equal to 01101111.


When does 2 plus 2 equal 11?

In a binary system, where only the digits 0 and 1 are used, the addition of 2 (represented as 10 in binary) and 2 (also represented as 10 in binary) equals 100 in binary, which is 4 in the decimal system. Therefore, in this specific context, 2 plus 2 equals 11.