I'm not sure if a byte by definition may be anything but 8 bit.
However, at least IBM have old irons with 9-bit characters. I assume that
they are using own-defined floating point data too.
For just about all machines in the world, the fp format is IEEE.
A double is then stored as
S EEEEEEEEEEE FFFFFFFFFFF.....FFFFF
0 1..11 12..63
E=2047, F!=0 -> Not a number
E=2047, F=0, S=1 -> -infinity
E=2047, F=0, S=0 -> +infinity
E!=0 -> normalized number -1^S * 2^(E-1023) * (1.F)
E=0, F!=0 -> unnormalized number -1^S * 2^(-1022) * 0.F
E=0, F=0, S=1 -> -0
E=0, F=0, S=0 -> +0
Similar for floating point, but
8-bit E, 23-bit F
Replace E=2047 with E=255
Replace (E-1023) with (E-127)
Replace 2^(-1022) with 2^(-126)
/Per W
On Mon, 7 Jul 2003, Ioannis Vranos wrote:
> 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=1;
>
> unsigned char *p=reinterpret_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=0; i<sizeof(d); ++i)
> {
> byte=p[i];
>
> for(unsigned j=0; j<byte.size(); ++j)
> cout<<byte[j];
> }
>
> 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
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL 1: http://run.to/noicys
> * Alternative URL 2: http://www.noicys.cjb.net
>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|