1

In case of float, IEEE-754 32-bit single precision format is used to store number in computer hardware.

storing floating point number in computer hardware

Here the most significant bit i.e. bit 31 is used to represent sign. It is either 0 or 1

  • 0 means positive number.
  • 1 means negative number.

The next 8 bits i.e. from bit 30 to 23 is used to represent exponent. It has a bias of 127.

The next 23 bits i.e. from bit 22 to 0 is used to represent mantissa.

For example we have the number (35.6)10.

  • The corresponding binary number is (100011.1001 1001 1001 ...)2
  • By normalizing the number we get (1.00011.1001 1001 1001 ... x 25)2
  • We remove the leading 1 and put the part right of radix point in the mantissa bit.
  • So, at the mantissa we put 00011 1001 1001 1001...
  • Adding exponent 5 to bias 127 we get 132
  • Binary of (132)10 is (10000100)2
  • We put 10000100 at exponent place
  • As (35.6)10 is positive we put 0 at place of sign bit

Thus the hardware level representation of (35.6)10 is

35.6 as stored in computer hardware


Double numbers are represented using IEEE-754 64-bit double-precision format.

storing double number in computer hardware

Here the most significant bit i.e. the bit 63 is used to represent sign. It is either 0 or 1.

The next 11 bits i.e. from bit 62 to 52 is used to represent exponent. It has a bias of 1023.

The next 52 bits i.e. from bit 51 to 0 is used to represent mantissa.


Similarly how decimal data type or fixed-point number is stored in computer hardware?

phuclv
  • 27,258
  • 11
  • 104
  • 360
Suraj
  • 531
  • 6
  • 14

2 Answers2

0

Fixed-point numbers are stored just like integers. The hardware does not maintain any information about the location of the binary point, just as the hardware doesn't now whether a stored value is signed or unsigned. It's up to the programmer or compiler to keep track of the fixed-point format of the variables and perform the correct operations on them.

It's not clear to me what you mean by a "decimal data type". If you are referring to BCD, then the data is again stored as an integer and the programmer/compiler has the responsibility of operating on it appropriately.

Elliot Alderson
  • 418
  • 2
  • 5
0

Fixed-point numbers are just series of bits in positional notation with their contribution to the final value predetermined, i.e. the position of the radix point is known at an exact place. Integers are just a subset of fixed-point numbers, with the radix point put on the right of the last bit (position 0)

That means fixed-point numbers are stored just as integers. However after each operation a shift (and possibly some other roundings) need to be made to move the radix point to the original position instead of position 0. Some architectures has hardware support for that, but most don't and the programmer is responsible for doing that


OTOH decimal datatype is not related to fixed-point numbers in anyway. It's just numbers in a different base (decimal instead of binary). Depending whether the point is fixed or movable we'll have fixed-point or floating-point decimal values. If it's floating then the exponent will be stored separately just like binary floating-point values

The decimal value's significant part is also an integer and there are various ways to store it. The simplest way is to store each digit in a byte. This is wasteful on memory and maybe slow to operate on in many cases. Another common encoding is BCD which stores a decimal digit in a nibble (since a nibble has 16 different states and is enough for 10 values). For packing the digits even more there's DPD which stores 3 decimal digits in 10 bits (uses 1000 of the 1024 different states). This is used in IEEE-754's decimal floating-point formats

phuclv
  • 27,258
  • 11
  • 104
  • 360