| | |
Binary to floating point representation
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
I am making a program that takes a binary number (a boolean array) and gives numerous representations.
For example, Enter binary (8 bits): 10001000
-Unsigned int: 136
-Hexadecimal: 88
-Octal: 210
-Two's complement: -120
-Sign magnitude: -8
-One's complement: -119
-Excess-127: 9
-ASCII: N/A
-Pep/8: SUBX immediate
-Floating-point: -0.125
I currently have all of the representations working, except floating-point. FP format would be 1 sign bit, 3 bit exponent (excess-3), and 4 bit significand. Does anyone have any suggestions on how to go about doing this? Thanks.
For example, Enter binary (8 bits): 10001000
-Unsigned int: 136
-Hexadecimal: 88
-Octal: 210
-Two's complement: -120
-Sign magnitude: -8
-One's complement: -119
-Excess-127: 9
-ASCII: N/A
-Pep/8: SUBX immediate
-Floating-point: -0.125
I currently have all of the representations working, except floating-point. FP format would be 1 sign bit, 3 bit exponent (excess-3), and 4 bit significand. Does anyone have any suggestions on how to go about doing this? Thanks.
I can give you the idea , but writing that entire program is up's to you.
First think that I convert 10101 to decimal. Think in simple.
= 2^0 * 1 + 2^1 * 0 + 2^2 *1 + 2^3 * 0 + 2^4 * 1 .......
so you can hard-code this , or you can implement a for loop until
you finish up to input binary number length. Just right shift by one
means multiply by two.
So you can easilly get an unsigned int.
Then start using this , you can typecast it to other data representations.
First think that I convert 10101 to decimal. Think in simple.
= 2^0 * 1 + 2^1 * 0 + 2^2 *1 + 2^3 * 0 + 2^4 * 1 .......
so you can hard-code this , or you can implement a for loop until
you finish up to input binary number length. Just right shift by one
means multiply by two.
So you can easilly get an unsigned int.
Then start using this , you can typecast it to other data representations.
![]() |
Other Threads in the C++ Forum
- Previous Thread: MFC help
- Next Thread: 2Gb output limit
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





