Intro. To Numbers Systems & How to convert between them.

Instructor: Khaled Ibrahim

Numbers Systems
Decimal Number System Binary Number System Hexadecimal Number System Octal Number System

Decimal Number System
The base & The system digits. The Base: 10 The system Digits: {0,1,2,3,4,5,6,7,8,9} X*100+X*101+X*102+……
Where X Can be any digit {0,1,2,3,4,5,6,7,8,9}

Example:
2547 :
7 + 40 +500 +2000 7*1 + 4*10 +5*100+2*1000 7*100 + 4*101 + 5*102 +2*103

Binary Number System
The Base: 2 The system Digits: {0,1} X*20+X*21+X*22+……
Where X Can be any digit {0,1} Write the number as a summation of powers of 2 {1,2,4,8,16,32,……..}

Example:
11 :
1 +2 +8 1*20 + 1*21 + 1*23

Binary Number System
Example:
17 :
1 + 16 1*20 + 1*24

Example:
27 :
1 + 2 + 8 + 16 1*20 + 1*21 + 1*23 + 1*24

Conversion From Decimal To Binary
Method 1
Step1 : N Mod 2, write the result from right to left. Step 2: N=N/2 Step 3: If N is less than 2 Then append N to the result. You are Done. Step 4: Else go to step 1

Conversion From Decimal To Binary
Example:
Find the binary value for 25 25 mod 2 12 mod 2 6 mod 2 Write the result from right to left 3 mod 2 1 mod 2

11001

Conversion From Decimal To Binary
Method 2
Step1 : Enumerate all the number that are powers of 2 and less than N Step 2: Start with the largest number and substitute it with 1. Step 3: Subtract this number from N and this value will be the new value for N. Step 4:If N equals 0 then you are Done Step 5: If N is greater than or equal to the next largest number then substitute it with 1 and go to step 3 else substitute it with 0 and go to step 5

Conversion From Decimal To Binary
Example:
Find the binary value for 25 16 8 2 1 1 1 0 1 9 1 0 0

Conversion From Binary To Decimal
Write the weights for binary digits above each digit. Add the weights that has a corresponding value one. Example:
Find the Decimal value for 110011 25 24 23 22 21 20 1 1 0 0 1 1 32 + 16 + 0 + 0 + 2 + 1 =51

Octal Number System
The Base: 8 The system Digits: {0,1,2,3,4,5,6,7} X*80+X*81+X*82+……
Where X Can be any digit {0,1,2,3,4,5,6,7}

Example:
11 :
3 +8 3*80 + 1*81

Octal Number System
Example:
17 :
1 + 16 1*80 + 2*81

Example:
27 :
3 + 24 3*80 + 3*81

Conversion From Decimal To Octal
Method 1
Step1 : N Mod 8, write the result from right to left. Step 2: N=N/8 Step 3: If N is less than 8 Then append N to the result. You are Done. Step 4: Else go to step 1

Conversion From Decimal To Octal
Example:
Find the Octal value for 25 25 mod 8 3 mod 8
Write the result from right to left

31

Conversion From Octal To Decimal
Write the weights for octal digits above each digit. Multiply each digit with its corresponding weight then add them all. Example:
Find the Decimal value for 245 82 81 80 2 4 5 2*64 +4*8 + 5*1=165

Hexadecimal Number System
The Base: 16 The system Digits: {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} X*160+X*161+X*162+……
Where X Can be any digit {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}

Example:
51 :
3 + 48 3*160 + 3*161

Hexadecimal Number System
Example:
17 :
1 + 16 1*160 + 1*161

Example:
25 :
9 + 16 9*160 + 1*161

Conversion From Decimal To Hexadecimal
Method 1
Step1 : N Mod 16, write the result from right to left. Step 2: N=N/16 Step 3: If N is less than 16 Then append N to the result. You are Done. Step 4: Else go to step 1

Conversion From Decimal To Hexadecimal
Example:
Find the Hex value for 20 20 mod 16 1 mod 16
Write the result from right to left

14

Conversion From Hexadecimal To Decimal
Write the weights for hex digits above each digit. Multiply each digit with its corresponding weight then add them all. Example:
Find the Decimal value for 2C1 162 161 160 2 12 1 2*256 +12*16 + 1*1=705