The story of cover: the first integreted circuit made by human.
Positional notation
In Positional notation, the value of content is determined by every character and its position.
Positional Numeral Systems
Positional Numeral Systems is a method for counting made by human, which is a method of positional notation.
For any of Positional numeral system, for example, N base, which means the front number will add 1 and current number becomes 0 when the current number meet N
- For decimal, it will add 1 to the front number and current number becomes 0 when current number meet 10
- For Hexadecimal, it will add 1 to the front number and current number becomes 0 when current number meet 16
- For binary, it will add 1 to the front number and current number becomes 0 when current number meet 2
- And so on…
So in N based, the character set of every position is {0, 1, 2, 3,..., N-1}
, we call the N base number.
For a N based number and its length is K, the maximum is N^K - 1
.
Decimal
Decimal is the most common positional numeral system in our daily life. The character set in decimal includes: 0-9.
For any decimal number, like 1938.5
and -224.2
:
|
|
For a decimal number and its length is K, the maximum is 10^K -1
.
Binary
Binary is the most common positional numeral system in computer.
Why computer cannot use decimal like human?
Because most of electrical components only have two stable status, like: the transistor’s on and off, the voltage’s high and low, > and Magnetic or not. Binary design can simplify the physical design of computer and improve the stability of the computer. (In theory, we can also build a computer which is not build on binary system)
For any binary number, like 1011.1
and -110.1
:
|
|
For a binary number and its length is K, the maximum is 2^K -1
.
Hexadecimal
As you can see, it’s too long when using binary to present a big number, but decimal cannot store in computer directly like binary, and it’s not convinent to convert between binary and decimal.
Oct(short for Octonary)and Hex (short for Hexadecimal) is for solving problem I mentioned above. We can talk about Hex first, which is more commonly used.
For presenting a number is a Hex number, we need to use 0x
as prefix, like:
|
|
Its character set includes: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
In hex number system, here’s the mapping relationship between alphabet and number:
|
|
For any Hex number, like 0x2D.F
:
|
|
For a hex number and its length is K, the maximum is 16^K - 1
.
Octonary
For presenting a number is a Oct number, we need to use 0
as prefix, like:
|
|
It’s character set includes: {0, 1, 2, 3, 4, 5, 6, 7}
For any oct number, like 023.7
:
|
|
For a oct number and its length is K, the maximum is 8^K - 1
.
Conversion
Others to decimal
Convert every number to decimal and add them all.
Binary to decimal
Like 110.11
:
|
|
Hex to decimal
Like 0x2AF.CB
:
|
|
As you can see, using hex to presenting a decimal is not convinent.
Oct to decimal
Like 0163.5
:
|
|
As you can see, using oct to presenting a decimal is not convinent either.
Decimal to others
The whole process of conversion has two parts: the integer part and the decimal part
- Integer part: using continuous division, deviding by base number until the quotient is 0 and putting all remainder in reverse order.
- Decimal part: using continuous multiplication, multiply by base number until the decimal is 0 and putting all integer in order.
Decimal to binary
Convert decimal number 17.625
to binary
Integer part:
|
|
Decimal part:
|
|
The result: 10001.101
Decimal to hex
Convert decimal number 17.625
to hex
Integer part:
|
|
Decimal part:
|
|
The result: 0x11.A
Decimal to oct
Convert decimal number 17.625
to oct
Integer part:
|
|
Decimal part:
|
|
The result: 021.5
Binary ⇄ Hex
Binary to hex
The process of Conversion has two parts as well: the integer part and the decimal part:
- Integer part: From the left of decimal point, converting every 4 (because 16 = 2^4) binary numbers to a hex number
- Decimal part: From the right of decimal point, converting every 4 (because 16 = 2^4) binary numbers to a hex number
Like binary number 100001001110.110101
Integer part:
|
|
Decimal part:
|
|
The result: 0x84E.D4
Hex to binary
Just reverse the process above, converting every hex number to 4 binary numbers
Like hex number 2FA.DE
|
|
The result: 1011111010.1101111
Minimum length for conversion
If a decimal integer X converts to N based, how many length to present the number after the conversion?
The maximum integer number which length is n and is N based number can present is N^n - 1
So if there is a situation exists that N^(n-1) - 1 < X <= N^n - 1
, which means that X needs to be presented in n-length after conversion.
For example: a decimal number 144
converts to binary number, since 2^7 - 1 < 144 < 2^8 - 1
144
needs a 8-length binary number to present at least.