Conversion to Binary and IEEE-754 Binary
|
06-27-2020, 01:35 PM
Post: #1
|
|||
|
|||
Conversion to Binary and IEEE-754 Binary
Converting to Binary
The program BASE2 can convert any real number in Base 10 to Base 2. This extends on the built in base conversions, which works on integers only. BASE2 returns a string with precision up to 23 bits. Negative numbers will have the negative sign instead of a 2's compliment. HP Prime Program BASE2 Code: EXPORT BASE2(s) Examples: BASE2(18.675) returns "10010.101011001100110011" BASE2(-4.3825) returns "-100.01100001111010111000" BASE2(π) returns "11.001001000011111101101" Converting to IEEE-754 Format The program IEEE754 converts any real number in decimal base to binary in IEEE-754 floating point format. A binary number in this format consists of a string of 32 bits: Bit 1 is the sign bit: 1 for negative numbers, 0 for positive numbers The next eight bits is the exponent bit: The exponent bit has a bias of 127. When converting to binary, 127 must be added to the exponent. (Example: 17 * 2^3. The exponent bit is 127 + 3 = 130). When converting to decimal, subtract 127 from the exponent word. The last 23 bits consist of the mantissa. The function returns a string with spaces between the sign, exponent, and mantissa sections for readability. HP Prime Program IEEE754 Code: EXPORT IEEE754(s) Example: IEEE754(2100) returns "0 10001010 100000110100000000000000" 2100 -> 100000110100_2 -> 1.00000110100_2 * (2_10) ^ (11_10) "moving the decimal point left 11 spaces" Exponent bit: 127 + 11 = 138 (138_10 -> 10001010_2) IEEE754(28.725) returns "0 10000011 11100101110011001100110" IEEE754(-19.5) returns "1 10000011 10011100000000000000000" Source: Sivaraman, Abishalini. "Decimal to IEEE 754 Floating Pont Representation" YouTube Video Published December 4, 2016 https://www.youtube.com/watch?v=8afbTaA-...4_mdWQE84q Petryk, Steve. "HOW TO: Convert Decimal to IEEE-754 Single-Precision Binary" YouTube Video. Published October 25, 2015. https://www.youtube.com/watch?v=tx-M_rqhuUA Blog link: http://edspi31415.blogspot.com/2020/06/h...-ieee.html |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Conversion to Binary and IEEE-754 Binary - Eddie W. Shore - 06-27-2020 01:35 PM
RE: Conversion to Binary and IEEE-754 Binary - Albert Chan - 06-27-2020, 08:37 PM
RE: Conversion to Binary and IEEE-754 Binary - Albert Chan - 06-29-2020, 01:33 PM
RE: Conversion to Binary and IEEE-754 Binary - Eddie W. Shore - 06-29-2020, 01:58 PM
RE: Conversion to Binary and IEEE-754 Binary - Eddie W. Shore - 08-02-2020, 02:51 PM
|
User(s) browsing this thread: 1 Guest(s)