Computer Fundamentals - Lecture_5- Numbring System
Computer Fundamentals - Lecture_5- Numbring System
Numbering Systems
Today Topics
Common Number Systems.
Data Representation.
Binary Operations
Binary Operations
Network Addresses
Image File
9.2
Number Systems - Why Binary?
9.5
Common Numbering Systems
Binary 2 0, 1
Octal 8 0, 1, 2, 3, 4, 5, 6, 7
Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 , A, B, C, D, E, F
9.6
Decimal Number System
Decimal number system is a base 10 number system having 10
digits from 0 to 9.
This means that any numerical quantity can be represented
using these 10 digits.
Decimal number system is also a positional value system. This
means that the value of digits will depend on its position.
Let us take an example to understand this.
Say we have three numbers – 734, 971 and 207. The value of 7 in all three
numbers is different−
In 734, value of 7 is 7 hundreds or 700 or 7 × 100 or 7 × 102
In 971, value of 7 is 7 tens or 70 or 7 × 10 or 7 × 101
In 207, value 0f 7 is 7 units or 7 or 7 × 1 or 7 × 100
9.7
Decimal Number System
The weightage of each position can be represented as
follows −
9.8
Binary Number System
Binary number system has two symbols: 0 and 1, called
bits.
This system is thus a base 2 number system.
As mentioned earlier, in the decimal system, each column
represents a higher power of ten, starting at the right end
with 100 , e.g.:
9.9
Binary Number System
Binary number system has two symbols: 0 and 1, called
bits.
This system is thus a base 2 number system.
As mentioned earlier, in the decimal system, each column
represents a higher power of ten, starting at the right end
with 100 , e.g.:
Likewise, in the binary number system, which is also
positional, each position represents a larger power of two,
starting with 20 on the right end of the whole number, as
displayed here.
9.10
Binary Number System (cont’d)
In any binary number, the rightmost digit is called least
significant bit (LSB) and leftmost digit is called most
significant bit (MSB).
9.11
Binary to Decimal Conversion
Multiply each binary bit by its column value
In binary, our columns are (from right to left)
20 = 1
21 = 2
22 = 4
23 = 8
24 = 16
25 = 32
Etc
Example
For the Binary Number: 101012, Calculating Decimal Equivalent −
Step Binary Number Decimal Number
Step 1 101012 ((1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20))10
10110 = 24 + 22 + 21 = 16 + 4 + 2 = 22
1100001 = 26 + 25 + 20 = 64 + 32 + 1 = 97
9.13
Powers of Two
20 1
21 2
22 4
23 8
24 16
25 32
26 64
27 128
28 256
29 512
210 1,024
9.14
Decimal to Binary Conversion
Follow the steps:
Divide the decimal number by 2
Keep the integer quotient for the coming iteration
Keep the remainder for the binary digit
Repeat the steps till you get 0 as your quotient
The binary number is the group of remainder bits written in opposite order
9.15
Decimal to Binary Conversion
Example: Convert 112 to binary
• 112 = 11100002
A6a5 a4 a3 a2 a1 a0
9.16
Decimal to Binary Conversion - Examples
Convert 200 to binary Convert 122 to binary
200 / 2 = 100 remainder 0 122 / 2 = 61 r 0
100 / 2 = 50 r 0 61 / 2 = 30 r 1
50 / 2 = 25 r 0 30 / 2 = 15 r 0
25 / 2 = 12 r 1 15 / 2 = 7 r 1
12 / 2 = 6 r 0 7/2 =3 r1
6/2 =3 r0 3/2 =1 r1
3/2 =1 r1 1/2 =0 r1
1/2 =0 r1 122 = 1111010
200 = 11001000
Convert 21 to binary
Convert 16 to binary
21 / 2 = 10 r 1
16 / 2 = 8 r 0
10 / 2 = 5 r 0
8/2 =4 r0
5/2 =2 r1
4/2 =2 r0
2/2 =1 r0
2/2 =1 r0
1/2 =0 r1
1 /2 = 0 r 1
21 = 10101
16 = 10000
9.17
Conversion From one radix to another
From decimal to base-r
Divide the number and all successive quotients by r
Example : convert (165)10 to base-7
165 / 7 = 23 remainder 4
23 / 7 = 3 remainder 2
3 / 7 = 0 remainder 3
(165)10 (324) 7
9.18
Decimal to Binary Conversion - Another Technique
Recall to convert from binary to decimal, we add the
powers of 2 for each digit that is a 1
To convert from decimal to binary, we can subtract all of the
powers of 2 that make up the number and record 1s in
corresponding columns Power of Decimal
Two Value
20 1
Example – Convert 19 to binary. 21 2
22 4
19 = 16 + 2 + 1 23 8
So there is a 16 (24), a 2 (21) and 0 (20) 24 16
25 32
Put 1s in the 4th, 1st, and 0th columns: 26 64
27 128
19 = 100112 28 256
29 512
210 1,024
9.19
Examples
Convert 122 to binary
Largest power of 2 <= 122 = 64 leaving 122 – 64 = 58
Power of Decimal
Largest power of 2 <= 58 = 32 leaving 58 – 32 = 26 Two Value
Largest power of 2 <= 26 = 16 leaving 26 – 16 = 10
20 1
Largest power of 2 <= 10 = 8 leaving 10 – 8 = 2 21 2
Largest power of 2 <= 2 = 2 leaving 0 22 4
Done 23 8
122 = 64 + 32 + 16 + 8 + 2 = 1111010 24 16
More examples: 25 32
26 64
555 = 512 + 32 + 8 + 2 + 1 = 1000101011
27 128
200 = 128 + 64 + 8 = 11001000
28 256
199 = 128 + 64 + 4 + 2 + 1 = 11000111
29 512
31 = 16 + 8 + 4 + 2 + 1 = 11111 210 1,024
60 = 32 + 16 + 8 + 4 = 111100
1000 = 512 + 256 + 128 + 64 + 32 + 8 = 1111101000
20 = 16 + 4 = 10100 9.20
Exercise
Convert the binary numbers to decimal:
1001001
00110
10111
11111
9.21
Number of Bits
Notice in our previous examples that for 555 we needed 10
bits and for 25 we only needed 5 bits
The number of bits available tells us the range of values we
can store
In 8 bits (1 byte), we can store between 0 and 255
00000000 = 0
11111111 = 255 (128 + 64 + 32 + 16 + 8 + 4 + 2 + 1)
In n bits, you can store a number from 0 to 2n-1
For 8 bits, 28 = 256, the largest value that can be stored
in 8 bits is 255
What about 5 bits?
What about 3 bits?
9.22
Bits and Bytes
The most basic unit of storage in a device is represented by a bit,
having a value of 1 or O.
Computers work with collections of bits, grouping them to represent
larger pieces of data, such as letters of the alphabet.
Eight bits make up one byte. A byte is the amount of memory needed
to store one alphanumeric character.
With one byte, the computer can represent one of 256 different symbols
or characters.
1 bit
8 bits = 1 byte
9.23
Data Representation
How is a letter converted to binary form and back?
Step 1.
The user presses Step 2.
the capital letter An electronic signal for the
D (shift+D key) capital letter D is sent to the
on the keyboard. system unit.
Step 4. Step 3.
After processing, the binary The signal for the capital letter D
code for the capital letter D is is converted to its ASCII binary
converted to an image, and code (01000100) and is stored in
displayed on the output device. memory for processing.
9.24
Binary Operations
9.27
Octal Numbers System Table
We use only 3 bits to represent Octal Numbers. Each group will have a distinct
value between 000 and 111.
9.28
Convert Decimal to Octal
Follow the steps:
Divide the decimal number by 8
Keep the integer quotient for the coming iteration
Keep the remainder for the octal number
Repeat the steps till you get 0 as your quotient
165 / 8 = 20 remainder 5
20 / 8 = 2 remainder 4
2 / 8 = 0 remainder 2
(165)10 = (245)8
9.29
Convert Binary to Octal
= (1 2 7 4 )8
= (1274)8
9.30
Convert Octal to Binary
Because each octal digit can be represented by a 3-bit
binary number, it is very easy to convert from octal to
binary..
Octal Digit 0 1 2 3 4 5 6 7
Binary 000 001 010 011 100 101 110 111
Example: Let’s convert the octal numbers 258 and 1408 to binary
2 5 1 4 0
010 101 001 100 000
101012 11000002
9.31
Hexadecimal Number System
The hexadecimal number system uses sixteen
digits/alphabets: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F with the
base number as 16.
Here, A-F of the hexadecimal system means the
numbers 10-15 of the decimal number system
respectively.
This system is used in computers to reduce the large-
sized strings of the binary system.
For example: 7B316, 6F16, 4B2A16 are some examples of
numbers in the hexadecimal number system.
9.32
Hexadecimal Numbers System Table
Decimal Binary Hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
9.33
Convert from Decimal to Hexadecimal
Convert the decimal number 650 to hexadecimal by
repeated division by 16.
650 / 16 = 40 remainder 10
40 / 16 = 2 remainder 8
2 / 16 = 0 remainder 2
6502 = 28A16
9.34
Convert Binary to Hexadecimal
Simply break the binary number into 4-bit groups, starting
at the right-most bit and replace each 4-bit group with the
equivalent hexadecimal symbol as in the following
example.
Convert the binary number (1100101001010111) to
hexadecimal:
Solution:
1100 1010 0101 0111
C A 5 7 = CA5716
9.35
Convert Hexadecimal to Decimal
Hexadecimal number system is also a positional value
system with where each digit has its value expressed in
powers of 16, as shown here:
Decimal Binary Hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3
1 C
0001 1100
Second: convert the binary to decimal:
9.38
Binary Operations
9.41
Binary Addition (cont’d)
With 3 bits (the two bits plus the carry), we have 4
possibilities:
0+0+0=0
2 zeroes and 1 one = 1
2 ones and 1 zero = 2 (carry of 1, sum of 0
3 ones = 3 (carry of 1 and sum of 1)
Example:
9.43
Network Addresses
Internet Protocol (IP) version 4 uses 32-bit addresses
Each of the numbers in this example represents 8 bits (or 1
byte) of the address, also known as an octet.
1 octet = 8 bits (0..255)
Each octet is separated by a period
The address 10.251.136.253
Stored as 00001010.11111011.10001000.11111101 in
binary
Omit the periods when storing the address in the
computer
9.44
Image Files
Images stored as sequences of pixels (picture elements)
row by row, each pixel is denoted by a value
A 1024x1024 pixel image will comprise 1024 individual dots
in one row for 1024 rows (1M pixels)
This file is known as a bitmap
In a black and white bitmap, we can store whether a pixel is
white or black with 1 bit
The 1024x1024 image takes 1Mbit (1 megabit)
A color image is stored using red, green and blue values
Each color can be between 0 and 255 (8 bits)
So each pixel takes 3 bytes
The 1024x1024 image takes 3MBytes
9.45
Black and white bitmap and its
corresponding binary file
9.46
Exercises
Convert 22310 into binary system.
9.47
Exercises
Convert the following binary numbers to decimal and
hexadecimal number system.
11010101
1110110
00011
100011
9.48