Professional Documents
Culture Documents
Bits, Bytes, Integers, and Floats Notes
Bits, Bytes, Integers, and Floats Notes
Bits, Bytes, Integers, and Floats Notes
Contents
Binary Representation ......................................................................................................... 2
Numeral Systems.............................................................................................................. 2
Base Conversion ............................................................................................................... 3
Integer ................................................................................................................................ 5
Signed vs unsigned ........................................................................................................... 5
Two’s complement ........................................................................................................... 6
Signed vs unsigned in Python ............................................................................................ 6
Python numbers. Integral .................................................................................................. 6
Real Numbers ...................................................................................................................... 7
Fixed-point numbers......................................................................................................... 7
Fixed-point numbers......................................................................................................... 8
Fixed-point numbers: accuracy problems ........................................................................... 8
Floating-point numbers..................................................................................................... 9
Floating point reference for Intel Architecture.................................................................... 9
Floating-point numbers................................................................................................... 10
Floating-point numbers: support ..................................................................................... 10
Floating-point numbers: accuracy problems ..................................................................... 11
Symbols and Characters ..................................................................................................... 11
Scalar data type: symbols and characters ......................................................................... 11
American Standard Code for Information Interchange ...................................................... 12
Several character set encoding ........................................................................................ 13
Handling Unicode ........................................................................................................... 13
Logical Operations ............................................................................................................. 14
Basic operation (addition) ............................................................................................... 14
Combinational circuits .................................................................................................... 15
Bit-level operations in Python.......................................................................................... 15
Bit-level operations in Python (cnt.) ................................................................................. 16
Logical operations in Python............................................................................................ 17
Conclusion......................................................................................................................... 18
Binary Representation
Numeral Systems
▪ Humans are accustomed to decimal (base 10) arithmetic
▪ A computer performs only binary (base 2) arithmetic
o Range: from 0 to 2ⁿ − 1
➢ for the purpose of shift and mask operations, a binary representation is assumed.
Real Numbers
Fixed-point numbers
➢ Bits = 1 + m + n
o 1 bit for sign (if signed)
o m bits for integer component
o n bits for fraction component
➢ Notation: Qm.n
o Integer number without fraction component Qm.0
o Fractional number without integer component Qn
Fixed-point numbers
➢ Bits = 1 + e + k
o 1 bit for sign (if signed)
o e bits for exponent 1, . . ., (2e − 1) – 1
o k bits for mantissa (fraction)
▪ There are an implicit 1-bit (top left) equals to 1, unless exponent
is equal to zero
➢ Quad-precision (128-bit)
o Software support
o Few architectures provide hardware support
o E.g. IBM POWER9 processors (MareNostrum 4)
Floating-point numbers: accuracy problems
Handling Unicode
o UTF-8: 1-byte for the first 127 code points (maintaining compatibility with
ASCII), and an optional additional 1-3 bytes (4 bytes total) for other
characters
➢ Operands:
Example: p = 5, q = 4, n = 3.
Combinational circuits