Sie sind auf Seite 1von 19

IEEE-754 Floating Point Converter

Translations: de

This page allows you to convert between the decimal representation of numbers (like
"1.02") and the binary format used by all modern CPUs (IEEE 754 floating point).

IEEE 754 Converter (JavaScript), V0.22


Exp
Manti
one
ssa
nt
2-126 0.0
Va (denor
(denor
lue malized
maliz
: )
ed)
En
co
de 0 0
d
as:
Bi
         
n
                
ar
   
y:
You entered
Value actually stored in float: +1
Error due to conversion: -1
Binary Representation
Hexadecimal Representation
 

Update

There has been an update in the way the number is displayed. Previous version would give
you the represented value as a possibly rounded decimal number and the same number
with the increased precision of a 64-bit double precision float. Now the original number is
shown (either as the number that was entered, or as a possibly rounded decimal string) as
well as the actual full precision decimal number that the float value is representing. Entering
"0.1" is - as always - a nice example to see this behaviour. The difference between both
values is shown as well, so you can easier tell the difference between what you entered and
what you get in IEEE-754.

This webpage is a tool to understand IEEE-754 floating point numbers. This is the
format in which almost all CPUs represent non-integer numbers. As this format is
using base-2, there can be surprising differences in what numbers can be
represented easily in decimal and which numbers can be represented in IEEE-754.
As an example, try "0.1". The conversion is limited to 32-bit single precision
numbers, while the IEEE-754-Standard contains formats with increased precision.

 Usage:

You can either convert a number by choosing its binary representation in the button-
bar, the other fields will be updated immediately. Or you can enter a binary number, a
hexnumber or the decimal representation into the corresponding textfield and press
return to update the other fields. To make it easier to spot eventual rounding errors,
the selected float number is displayed after conversion to double precision.

 Special Values:

You can enter the words "Infinity", "-Infinity" or "NaN" to get the corresponding
special values for IEEE-754. Please note there are two kinds of zero: +0 and -0.

 Conversion:

The value of a IEEE-754 number is computed as:

sign 2exponent mantissa

The sign is stored in bit 32. The exponent can be computed from bits 24-31 by
subtracting 127. The mantissa (also known as significand or fraction) is stored in bits
1-23. An invisible leading bit (i.e. it is not actually stored) with value 1.0 is placed in
front, then bit 23 has a value of 1/2, bit 22 has value 1/4 etc. As a result, the mantissa
has a value between 1.0 and 2. If the exponent reaches -127 (binary 00000000), the
leading 1 is no longer used to enable gradual underflow.

 Underflow:

If the exponent has minimum value (all zero), special rules for denormalized values
are followed. The exponent value is set to 2-126 and the "invisible" leading bit for the
mantissa is no longer used.

The range of the mantissa is now [0:1).

Note: The converter used to show denormalized exponents as 2-127 and a


denormalized mantissa range [0:2). This is effectively identical to the values above,
with a factor of two shifted between exponent and mantissa. However this confused
people and was therefore changed (2015-09-26).

 Rounding errors:

Not every decimal number can be expressed exactly as a floating point number. This
can be seen when entering "0.1" and examining its binary representation which is
either slightly smaller or larger, depending on the last bit.

 Other representations:

The hex representation is just the integer value of the bitstring printed as hex. Don't
confuse this with true hexadecimal floating point values in the style of 0xab.12ef.
 FAQ (Frequently Asked Questions):
o Can you send me the source code? I need to convert format x to format
y.:

This source code for this converter doesn't contain any low level conversion
routines. The conversion between a floating point number (i.e. a 32 bit area in
memory) and the bit representation isn't actually a conversion, but just a
reinterpretation of the same data in memory. This can be easily done with
typecasts in C/C++ or with some bitfiddling via java.lang.Float.floatToIntBits in
Java. The conversion between a string containing the textual form of a
floating point number (e.g. "3.14159", a string of 7 characters) and a 32 bit
floating point number is also performed by library routines. If you need to write
such a routine yourself, you should have a look at the sourecode of a
standard C library (e.g. GNU libc, uclibc or the FreeBSD C library - please
have a look at the licenses before copying the code) - be aware, these
conversions can be complicated.

o Can you add support for 64-bit float/16-bit float/non-IEEE 754 float?.:

This page relies on existing conversion routines, so formats not usually


supported in standard libraries cannot be supported with reasonable effort.
Double-precision (64-bit) floats would work, but this too is some work to
support alongside single precision floats. As the primary purpose of this site is
to support people learning about these formats, supporting other formats is
not really a priority.

o I've converted a number to floating point by hand/some other method,


and I get a different result. Your converter is wrong!

Possible, but unlikely. The conversion routines are pretty accurate (see
above). Until now, checking the results always proved the other conversion
less accurate. First, consider what "correct" means in this context - unless the
conversion has no rounding error, there are two reasonable results, one
slightly smaller the entered value and one slightly bigger. The best result is
usually the one closer to the value that was entered, so you should check for
that. Please check the actual represented value (second text line) and
compare the difference to the expected decimal value while toggling the last
bits.

How to Convert a Number from Decimal to IEEE 754


Floating Point Representation
Author Info

Unlike humans, computers do not utilize the base 10


number system. They use a base 2 number system
that allows for two possible representations, 0 and 1.
Thus, numbers are written very differently in IEEE 754
than in the traditional decimal system that we are
used to. In this guide, you will learn how to write a
number in both IEEE 754 single or double precision
representation.
For this method, you will need to know how to convert
numbers into binary form. If you don't know how to do
this, you can learn how in How to Convert from
Decimal to Binary.
StepsEdit
1.

1
Choose single or double precision. When writing a
number in single or double precision, the steps to a
successful conversion will be the same for both, the
only change occurs when converting the exponent
and mantissa.

 First we must understand what single


precision means. In floating point representation,
each number (0 or 1) is considered a “bit”.
Therefore single precision has 32 bits total that are
divided into 3 different subjects. These subjects
consist of a sign (1 bit), an exponent (8 bits), and a
mantissa or fraction (23 bits).
 Double precision, on the other hand, has the
same setup and same 3 parts as single precision;
the only difference is that it will be larger and more
precise number. In this case, the sign will have 1
bit, the exponent will have 11 bits and the
mantissa will have 52 bits.
 In this example will convert the number
85.125 into IEEE 754 single precision.
2.

2
Separate the whole and the decimal part of the
number. Take the number that you would like to
convert, and take apart the number so you have a
whole number portion and a decimal number portion.
This example will use the number 85.125. You can
separate that into whole number 85, and the decimal
0.125.

3.

3
Convert the whole number into binary. This
would be the 85 from 85.125, which will be 1010101
when converted into binary.

4.

4
Convert the decimal portion into binary. This
would be the 0.125 from 85.125, which will be 0.001
when converted into binary.

5.

5
Combine the two parts of the number that have
been converted into binary. For instance, the
number 85 in binary is 1010101 and the decimal
portion 0.125 in binary is .001. When you combine
them using a decimal point, you end up with
1010101.001 as your final answer.
6.

6
Convert the binary number into base 2 scientific
notation. You can convert the number into base 2
scientific notation by moving the decimal point over
to the left until it is to the right of the first bit. These
numbers are normalized which means the leading bit
will always be 1. As for the exponent, the number of
times that you moved the decimal will be your
exponent in base 2 scientific notation.

 Remember that moving the decimal to the


left will result in a positive exponent while moving
the decimal to the right will result in a negative
exponent.
 For our example, you will need to move the
decimal 6 times in order to get it to the right of the
first bit. The resulting notation will be  , this
number will be used in future steps.
7.

Error! Filename not specified.


7
Determine the sign of the number and display
in binary format. You will now determine if your
original number is positive or negative. If the number
is positive, you will record that bit as 0, and if it is
negative, you will record that bit as 1. Since your
original number, 85.125, is positive, you will record
that bit as 0. This will be the first bit out of the 32
total bits in your IEEE 754 single precision
representation.

8.

Error! Filename not specified.

8
Get the exponent based on precision. There are
set biases for both single and double precision. The
exponent bias for single precision is 127, which
means we must add the base 2 exponent found
previously to it. Thus, the exponent you will use
is 127+6 which is 133.

 Double precision as perceived from the name


is more precise and can hold larger numbers.
Therefore its exponent bias is 1023. The same
steps used for single precision apply here, so the
exponent you can use to find double precision is
1029.
9.

Error! Filename not specified.

9
Turn the exponent into binary. After you
determine your final exponent, you will need to
convert it into binary so that it could be used in the
IEEE 754 conversion. For the example, you can
convert the 133 that you found in the last step into
10000101.

10.

Error! Filename not specified.

10
Determine the mantissa. The mantissa aspect, or
the third part of the IEEE 754 conversion, is the rest
of the number after the decimal of the base 2
scientific notation. You will just drop the 1 in the front
and copy the decimal portion of the number that is
being multiplied by 2. No binary conversion needed!
For the example, the mantissa would be 010101001
from .

11.

Error! Filename not specified.

11
Compile 3 parts into one final number.

 Finally, you will compile all that we have


calculated thus far into your conversion. It will first
begin with a 0 or 1 bit that you determined in step
7 based on sign. For the example, you will have a 0
to start it.
 Next up, you will have the exponent section
that you determined in step 9. For the example,
your exponent will be 10000101.
 Now, you have the mantissa, which is the
third and last part of the conversion. You derived
this earlier when you took the decimal portion of
the base 2 conversion. For the example, the
mantissa would be 010101001.
 Finally, you combine these all together. The
order should go sign-exponent-mantissa. After you
connect those three binary numbers, you then fill
out the rest of the mantissa with 0s.
 For the example the solution is 0 10000101
01010100100000000000000 as 85.125
converted into IEEE 754 format.

Advertisement

Community Q&A
Ask a Question
Submit
Related wikiHows

Error! Filename not specified.

How to
Convert Milliliters (mL) to Grams (g)

Error! Filename not specified.

How to
Calculate BTU Per Square Foot

Error! Filename not specified.

How to
Convert Pounds to Kilograms

Error! Filename not specified.


How to
Calculate Volume in Litres

Error! Filename not specified.

How to
Convert Hexadecimal to Binary or Decimal

Error! Filename not specified.

How to
Convert from Decimal to Binary

Error! Filename not specified.

How to
Convert Centimeters to Inches

Error! Filename not specified.

How to
Convert Binary to Hexadecimal

Error! Filename not specified.


How to
Convert Cm to M

Error! Filename not specified.

How to
Convert Minutes to Hours

Error! Filename not specified.

How to
Convert from Binary to Decimal

Error! Filename not specified.

How to
Convert Seconds to Minutes

Error! Filename not specified.

How to
Convert Feet to Meters

Error! Filename not specified.


How to
Calculate Cubic Inches
Advertisement

About This Article


wikiHow is a wiki similar to Wikipedia, which means that
many of our articles are written collaboratively. To create this
article, volunteer authors worked to edit and improve it over
time. This article has also been viewed 18,406 times.
105 votes - 89%
Co-authors: 8
Updated: 22 hours ago
Views: 18,406
Categories: Conversion Aids
Did this article help you?
Yes
No
 Steps
 Community Q&A
 Related wikiHows
Surprise Me!

   

   
 
Mad Irish . net
 about
 contact
 gpg key
 rss
 github
 LAMPSecurity
 twitter

Converting a Decimal Digit to


IEEE 754 Binary Floating Point
how to

30 November -0001

IEEE 754 Binary Floating Point is a 32-bit representation (for single precision, 64 bits are
used for double precision) for floating point numerals. The 32-bit representation consists of
three parts. The first bit is used to indicate if the number is positive or negative. The next 8
bits are used to indicate the exponent of the number, and the last 23 bits are used for the
fraction.
Converting decimal digits to IEEE binary floating point is a little tricky. The purpose of this
article is to outline a simple method for completing this conversion.
The first step in the conversion is the simplest. This is determining the first bit. If the decimal
digit is positive then this bit is 0, if the decimal digit is negative then this bit is 1.
The next eight digits are used to express the exponent, which we'll figure out last.
The final 23 digits are used to express the fraction. This gives you 2^23 precision. The first
thing to do is convert your decimal digit to binary, ignoring any positive or negative signs.
For instance, if your original number was:
-210.25

you first need to convert 210.25 to binary. It is easiest to focus on the integer part of the
number first, then the decimals. 210 is 11010010 or 128+64+16+2, otherwise expressed as:
1*2^7 + 1*2^6 + 0*2^5 + 1*2^4 + 0*2^3 + 0*2^2 + 1*2^1 + 0*2^0

Next we need to convert the decimal part. To do this we have to convert the number into a
binary sequence that equals a*2  + a*2  and so on. This series basically means 1/2 + 1/4 + 1/8
-1 -2

+ 1/16 and so on. Luckily .25 is 1/4 and so this is easy to calculate. It is .01 or 0*2  + 1*2 .
-1 -2

So our final number is 11010010.01. The next step is to normalize this number so that only
one non zero decimal place is in the number. To do this you must shift the decimal place 7
positions to the right left. The number 7 becomes important so we note it. This process leaves
us with the number 1.101001001 which is the fraction that is represented in the last 23 bit
places in the 32 bit binary. However, because of the rules used for conversion the first digit of
any number will always be one. Because we know this number there is no need to represent
it. Thus the number we will represent is 101001001. This is then padded with 0's to fill in the
full 23 bits - leaving us with 10100100100000000000000.
So we now have the first bit, and the last 23 bits of the 32 bit sequence. We must now derive
the middle 8 bits. To do this we take our exponent (7) and add 127 (the maximum number
you can express with 8 bits (2^8-1 or the numbers 0 to 127)) which gives us 134. We then
express this number as an 8 bit binary. This is 10000110 (or 1*2^7 + 1*2^2 + 1*2^1 or
128+4+2). Now we have the middle bits.
Taken as a whole our bit sequence will be:
1 10000110 10100100100000000000000

We can convert this bit sequence back into a number by reversing the process. First we can
note by the leading 1 that the number is negative. Next we can determine the exponent.
10000110 is binary for 2+4+128 or 134. 134-127 is 7, so the exponent is 7. Finally we take
the last 23 digits, convert them back into the original fraction (adding the preceding 1.) to get:
1.101001001

Moving the decimal place to the right by 7 (corresponding to the exponent) we get:
11010010.01

This binary is equal to 128+64+16+2 + 1/4 or 210.25. Once we apply the negative sign
(indicated by the leading bit set to 1) we get our original number:
-210.25

References:

http://en.wikipedia.org/wiki/IEEE_754

Tags
 apple
 arbitrary code execution
 blue team
 disclosure
 drupal
 editorial
 encryption
 exploit
 feature
 how to
 html 5
 ios
 iot
 javascript
 linux
 malware
 mysql
 network
 os x
 pen test
 php
 privacy
 random
 raspberry pi
 research
 review
 sql
 sql injection
 tools
 tutorial
 vuln
 web application
 windows
 xss
Copyright © Justin C. Klein Keane. Unauthorized reproduction is a violation of US and international
law.
IEEE 754 Notation

Example: Converting to IEEE 754 Form

Put 0.085 in single-precision format

1. The first step is to look at the sign of the number.


Because 0.085 is positive, the sign bit =0. 

(-1)0 = 1.

2. Write 0.085 in base-2 scientific notation.


This means that we must factor it into a number in the range [1 <=
n < 2] and a power of 2.

0.085 = (-1)0  *  (1+fraction)   * 2 power,    or: 


0.085 / 2power = (1+fraction). 

So we can divide 0.085 by a power of 2 to get the (1 + fraction). 

0.085 / 2-1 = 0.17


0.085 / 2-2 = 0.34
0.085 / 2-3 = 0.68
0.085 / 2-4 = 1.36

Therefore, 0.085 = 1.36 * 2-4

3. Find the exponent.


The power of 2 is -4, and the bias for the single-precision format is
127. This means that the exponent = 123ten, or 01111011bin

4. Write the fraction in binary form


The fraction = 0.36 . Unfortunately, this is not a "pretty" number,
like those shown in the book. The best we can do is to
approximate the value. Single-precision format allows 23 bits for
the fraction.

Binary fractions look like this:

0.1 = (1/2) = 2-1


0.01 = (1/4) = 2-2
0.001 = (1/8) = 2-3
To approximate 0.36, we can say:

0.36 = (0/2) + (1/4) + (0/8) + (1/16) + (1/32) +...


0.36 = 2-2 + 2-4 + 2-5+... 

0.36ten ~ 0.01011100001010001111011bin .

The binary string we need is: 01011100001010001111011.

It's important to notice that you will not get 0.36 exactly. This is
why floating-point numbers have error when you put them in IEEE
754 format.

5. Now put the binary strings in the correct order - 


1 bit for the sign, followed by 8 for the exponent, and 23 for
thefraction. The answer is:

6. Sign Exponent Fraction

Decimal 0 123 0.36

Binary 0 01111011 01011100001010001111011

Example: IEEE 754 to Float ->

Das könnte Ihnen auch gefallen