| | |
a simple way to print a binary representation of a floating point number?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 1
Reputation:
Solved Threads: 0
Hi everybody,
is there a simple way to print a floating point number in its internal representation
(i.e. binary or hex) in C(C++)? Yet another question -- is there a linux utility to do the opposite thing with a binary file (i.e. choose a range of bits and convert it to a floating point number)?
Thanks.
Best regards,
Nick.
is there a simple way to print a floating point number in its internal representation
(i.e. binary or hex) in C(C++)? Yet another question -- is there a linux utility to do the opposite thing with a binary file (i.e. choose a range of bits and convert it to a floating point number)?
Thanks.
Best regards,
Nick.
Something like this?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Dec 2004
Posts: 60
Reputation:
Solved Threads: 1
•
•
•
•
Originally Posted by nsavvinv
Hi everybody,
is there a simple way to print a floating point number in its internal representation
(i.e. binary or hex) in C(C++)? Yet another question -- is there a linux utility to do the opposite thing with a binary file (i.e. choose a range of bits and convert it to a floating point number)?
Thanks.
Best regards,
Nick.
C++ Syntax (Toggle Plain Text)
#include <iostream.h> main() { double x, mant; int exp = 0; cout << "Enter postive x: "; //Now find exponent and mantissa mant = x; while (mant >= 1) { mant /= 2; exp++; // At this point x = mant * 2^(exp) } while (mant < 0.5) { mant *= 2; exp--; } cout << x<<" is stored in the computer as \n"<< x <<" = "; cout <<"2^(" <<exp<<") *."; while (mant > 0) { mant *= 2; if (mant >= 1) { cout << '1'; mant -= 1; } else cout << '0'; } cout << endl; }
I hope I haven't incorrectly entered this code. I have to find out how to upload a code from my hard disk.
![]() |
Similar Threads
- Floating point in Assembly (Assembly)
- MIPS floating point registers (Assembly)
- HELP Concert Floating Point to ASCII String... (Assembly)
- IEEE Floating-point fromat (C)
Other Threads in the C++ Forum
- Previous Thread: C++ Integer to String function
- Next Thread: Function Not Returning Value??
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets







...