Decimal Numbers
Integer : 1000 100 10 1
1964 = 1 x 10^3 + 9 x 10^2 + 6 x 10^1 + 4 x 10^0
Fraction: 1/10 1/100 1/1000 1/10,000
0.1964 = 1 x 10^-1 + 9 x 10^-2 + 6 x 10^-3 + 4 x 10^-4
Million: 10^6 (Million)
Billion: 10^9 (Milliarde in German)
Trillion: 10^12 (Billion in German)
Quadrillion: 10^15 (Billiarde in German)
Note there is a difference in English and German/French in large numbers.
Similarly 1.23 is an English floating points and 1,23 is the same in German/French (use of comma versus point).
The U.S. dept is $ 33 Trillion or $ 100 thousand per U.S. citizen.
There are 10^80 atoms in the observable universe.
There are 10^24 stars in the universe or billions of trillions.
A hydrogen atom has a diameter of 10^-12 meters (pico meter).
Roman Numerals
I = 1
V = 5
X = 10 (decem, perhaps two Vs)
L = 50
C = 100 (centum, a centurion commands 100 men)
D = 500
M = 1000 (mille)
A smaller symbol in front of larger symbol is a subtraction, and after a larger symbol is an addition
1964 = MCMLXIV = 1000 + (-100+1000) + (50+10) + (-1+5)
Computing Terms
Bit (basic unit 1 or 0, true or false, high or low)
Nibble (4 bit)
Octet (8 bit) or Byte
Word (amount of data a computer can process at a time, Raspberry Pi 3,4 and 5 is 64 bit)
Examples
192.168.0.1 is the internet protocol address (IPv4) of a computer. There are 256^4 different addresses (four Billion).
In a 32 bit computer, adding 8bit, 16 bit or 32bit integer takes the same amount of time, but adding 64bit (long) has to be done in multiple steps. Most computers these days are 64bit.
Hexadecimal
Alternatives are 0..9,A,B,C,D,E,F = 0..15 in decimal
FA = 15 (the F) * 16^1 + 10 (the A) * 16 ^ 0 = 250 decimal
Example MAC address of an internet adapter
fe80:5437:75a1:4f03:e00a these are 5 * 16 bit representing 1 quadrillion alternatives (10^15).
Binary
0,1 are the alternatives
8 bit Integer
1001,1011 = 1 x 2^7 + 0 x 2^6 + 0 x 2^5 + 1 x 2^4 + 1 x 2^3 + 1 x 2^1 + 1 x 2^0 = 155
8 bit Fraction (used for floating point numbers)
0.1011 = 1 x 2^-1 + 0 x 2^-2 + 1 x 2^-3 + 1 x 2^-4
Binary and Hexadecimals
FF = 1111,1111 binary
FA = 1111,1010 binary
a hexadecimal digit represents a nibble which consists of 4 bits. Two nibbles is one byte. Therefore two hexadecimal numbers represent on byte.
Adding two Binary Numbers
1010
+ 0011
======
1101 Result
1 carry forward because 1+1 = 10 in binary
Negative Binary Number is accomplished with 2's complement
1010 = 10
create 2' complement: invert and add 1 (convention)
0101 + 1
0110 = -10
Now we add the 2's complement to the original number (10 + -10 = 0)
1010
+ 0110
====
(1)0000
11 carry forwards
truncate to 4 bits because we only work with 4 digits in this example.
0000 is 0
This means if you have hardware to add two binary numbers you only need hardware to invert a number and you also have the ability to subtract.
Floating point
We want to represent +5.75 . For special cases we alsos need to define zero, plus infinite, minus infinite and "not a number" (as result for sqrt(-1) for example).
We can write this as (+) 0.575 x 10^1 where 575 is the mantissa and 1 is the exponent.
In binary we write (-1)^sign x 1.0111 x 2 ^ (1000 0001 - 0111 1111) which is explained below.
Floating Point Number (IEEE 754 standard)
We use a Sign Bit, an Exponent, a Mantissa. Let's look at 32 bit floating point numbers.
32 bits are organized the following way:
Sign | Exponent (8bits) | Mantissa (23 bits) | to a total of 32 bits
0 | 10000001 | 01110000000000000000000 |
This represents:
(-1)^sign x 1.mantissa × 2^(exponent - bias)
The bias is 127 for 32 bits (half the range of 8 bit, full range is 255)
Sign:
(-1)^0 = 1
Exponent:
10000001 = 129 (dec)
129-127 = 2
2^2 = 4 (dec)
Mantissa as a Fraction:
01110000000000000000000 = (1 +) 0 x 2^-1 + 1 x 2^-2 + 1 x 2^-3 + 1 x 2^-4 + 0 x .... =
1.4375
All together:
1 * 1.4375 * 4 = 5.75
Special Numbers
Zero = 0
Not a Number (NAN) = sqrt(-1) or 0/0
+Infinity = 1/0
-Infinity = -1/0
To Multiply or Add floating point numbers you need an algorithm or a special hardware (floating point unit).
Some inexpensive micro controllers don't have floating point instructions and computing floats is accomplished in software taking much longer than integer math. For example 20.31 Celsius to Kelvin is 20.31 + 273.15. You can decide to represent this temperature as 2031. Then Kelvin will be 2031 + 27315 which is integer math. When you display it you divide by 100 to obtain the quotient and remainder also in integer math. You dont worry about this in python or on regular computer, but this matters for low cost micro controller.