[Dev-C++] Question about bit representation
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-07-07 11:19:20
|
In a newsgroup out there there was a girl who wanted to see the
representation of a given double in her system. All others provided low
level messy stuff involving & operators etc.
I provided the code:
#include <iostream>
#include <bitset>
#include <limits>
int main()
{
using namespace std;
double d=3D1;
unsigned char *p=3Dreinterpret_cast<unsigned char *>(&d);
// There are systems where 1 byte is more than 8 bits
bitset<numeric_limits<unsigned char>::digits> byte;
for(unsigned i=3D0; i<sizeof(d); ++i)
{
byte=3Dp[i];
for(unsigned j=3D0; j<byte.size(); ++j)
cout<<byte[j];=20
}
=20
cout<<endl;
}
However it seems to be printed in the opposite way (try making d an =
unsigned
char). Perhaps it is the way it is implemented in the system, or I am =
taking
something in the opposite way that I can't find out?
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|