You are on page 1of 2

1.

Converting floating-point numbers from the hexadecimal into the decimal format

The following diagram shows the arrangement of bits of IEEE floating-point numbers. Bit 31 =
sign, bits 23 to 30 = exponent and bits from 0 to 22 = mantisse.

Bit
31 24 23 16 15 8 7 0
V E E E E E E E E M M M M M M M M M M M M M M M M M M M M M M M
Exponent Mantisse
Sign

The representation of a floating-point number (-1)VZ · m · 2e comprises:


ƒ VZ = sign (0 – positive, 1 – negative)
ƒ e = exponent (e = exp - 127)
ƒ m = mantisse (m = 1.M ; 1 <= m < 2)

The sign, exponent (exp) and the decimal point (M) of the number are saved in a floating-point
number. They still have to be determined.

The following schematic shows how all of the three components are selected. In this case the
maximum frequency is considered (50.0Hz float: 4248 0000 hex ⇒ 50.0 dec)

4 2 4 8 0 0 0 0

Bit
31 24 23 16 15 8 7 0
0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
… … … …

8 4 9 0

84hex = 132dec 1/16 1/162

Exponent (Exp) Mantisse (M) – decimal place in the hex system

Sign (VZ)

The number comprises the following elements:

(-1)VZ ·1.M·2Exp-127 = (-1)0 ·(1 + 9·(1/16) + 0·(1/162))·2132-127 = 1·1.5625·25 = 50.0


2. Converting floating-point numbers from the decimal into the hex format

The decimal number must be represented in the form (-1)VZ · 1.M · 2Exp - 127.
Let's consider this conversion using an example.
The maximum frequency (P1082) should, e.g. be set to 87.0Hz; to do this the following
conversion is required:

• Sign "+" ⇒ 87=(-1)0·87

• Which power of 2 fits in the number so that the rest results in a "one (decimal) point
something"?

26 = 64 ⇒

87 = 64 · (87/64) =

• Subtract 1 according to the definition

= 26 · (1 + 87/64 – 1) =

= 26 · (1 + (87/64 – 64/64)) =

• Represent 6 as 133-127 according to the definition

= 2133-127 · (1 + 23/64) =

• The value 23/64 must be represented as a multiple of 1/16, 1/256 etc.

= 2133-127 · (1 + 92/256) =

= 2133-127 · (1 + (80+12)/256) =

= 2133-127 · (1 + 5/16 + 12/256) ⇒

⇒ VZ = 0,
Exp = 133dec = 85hex,
Mantisse = 5.12dec

VZ Exponent (Exp) Mantisse (M)

0 8 5 5 12

0 1 0 0 0 0 1 0 1 0 1 0 1 1 1 0 0 …

4 2 A E 0 0 0 0
Send via Profibus: 42AE 0000.

You might also like