12-CN-Chap6-Conversion binary to Decimal,Hexadecimal
12-CN-Chap6-Conversion binary to Decimal,Hexadecimal
Chapter 6
Binary to Decimal, Hexadecimal Conversion
‣ The value of each digit position is the value of its digit, multiplied by a power of the base.
The power is determined by the digit's position.
‣ The value of a positional number is the total of the values of its positions.
6-2
Binary System
‣ A binary number is a number expressed in the base-2 numeral system
• Uses only two symbols: 0 and 1
• A single binary digit is called a bit.
6-3
6-4
6-5
6-6
6-7
(Base 10) (Base 2) (Base 16)
6-8
6-9
Examples:
DIGIT × BASE #POSITION
Decimal Number:
4567
= 4000 + 500 + 60 + 7
= (4 × 1000) + (5 × 100) + (6 × 10) + (7 × 1)
= (4 × 10 ) + (5 × 10 ) + (6 × 10 ) + (7 ×10 )
3 2 1 0
Binary to decimal:
(11101)2 =
(1×2 )+(1×2 )+(1×2 )+(0× 2 )+(1×2 )
4 3 2 1 0
(1FA)16=
(1×16 )+(F×16 )+(A×16 )=(1×16 )+(15×16 )+(10×16 )=506d
2 1 0 2 1 0
6-10
Decimal to Binary
4410 to base 2
(44)10 = (101100)2
Decimal to Hexadecimal
3110 ? hexadecimal
3110 = 1F16
31/16 = 1 remainder = 15
1/16 = 0 remainder = 1
6-11
Binary to Hexadecimal
base 16 =24
Each bit in hexadecimal is expanded over 4bits in binary and vice-versa
Base16: 0, 1, … 9, A, B, C, D, E, F
Example :
F16 = 1111
Convert 1111012 to Hexadecimal
Hexadecimal to Binary
convert 3D16 to Binary
316 =00112
D16 =11012
3D16 = 0011 11012
6-12
Binary and IPv4 Addresses
6-13
6-14
6-15
The binary positional notation system operates as shown in the tables below.
Radix 2 2 2 2 2 2 2 2
Position in Number 7 6 5 4 3 2 1 0
Result 192
6-16
Binary Number System
Convert Binary to Decimal
Convert 11000000.10101000.00001011.00001010 to decimal.
Positional Value 128 64 32 16 8 4 2 1
6-17
Binary Number System
Decimal to Binary Conversion Example
• Convert decimal 168 to binary
Is 168 > 128?
- Yes, enter 1 in 128 position and subtract 128 (168-128=40)
Is 40 > 64?
- No, enter 0 in 64 position and move on
Is 40 > 32?
- Yes, enter 1 in 32 position and subtract 32 (40-32=8)
Is 8 > 16?
- No, enter 0 in 16 position and move on
Is 8 > 8?
- Equal. Enter 1 in 8 position and subtract 8 (8-8=0)
No values left. Enter 0 in remaining binary positions
128 64 32 16 8 4 2 1
1 0 1 0 1 0 0 0
Decimal 168 is written as 10101000 in binary
6-18
Binary Number System
IPv4 Addresses
• Routers and computers only understand binary, while humans work in decimal.