0% found this document useful (0 votes)
10 views

Computer Fundamentals - Lecture_5- Numbring System

Uploaded by

randsand97
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Computer Fundamentals - Lecture_5- Numbring System

Uploaded by

randsand97
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 48

Computer Fundamentals

Numbering Systems
Today Topics
 Common Number Systems.

 Binary to Decimal Conversion & vise versa.

 Data Representation.

 Binary Operations

 Octal Number System

 Binary Operations

 Network Addresses

 Image File

9.2
Number Systems - Why Binary?

 Early computer design was decimal

 John von Neumann proposed binary


data processing (1945)
 Simplified computer design
 Used for both instructions and data IBM 650 - 1950s
 Natural relationship between
on/off switches and
calculation using Boolean logic
On Off
True False
Yes No
1 0 9.3
Numbering Systems
 Computers only deal with binary data (0s and 1s).
 All data manipulated by computers must be represented in
binary format.
 Machine instructions manipulate many different forms of data:
 Numbers:
 Integers: 33, +128, -2827
 Real numbers: 1.33, +9.55609, -6.76E12, +4.33E-03
 Alphanumeric characters (letters, numbers, signs, control characters):
examples: A, a, c, 1 ,3, ", +, Ctrl, Shift, etc.
 Images (still or moving): Usually represented by numbers representing the
Red, Green and Blue (RGB) colors of each pixel in an image,
 Sounds: Numbers representing sound amplitudes sampled at a certain rate
(usually 20kHz).
 In general we have two major data types that need to be represented in
computers; numbers and characters.
9.4
Common Numbering Systems
 The most widely used numbering systems are listed in
below:
 Binary number system
 Octal number system
 Decimal number system
 Hexadecimal (hex) number system

9.5
Common Numbering Systems

Name Base Symbols

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 −

Examples of positional notation:

199610 = 1 x 103 + 9 x 102 + 9 x 101 + 6 x 100


200010 = 2x103

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.:

 The highest decimal number that can be represented by n


bits binary number is 2n – 1.
 Thus with an 8 bit number the maximum decimal number
that be represented is 28 – 1 is 255.

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).

And decimal equivalent of this number is sum of product of each digit


with its positional value.

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

Step 2 101012 (16 + 0 + 4 + 0 + 1)10

Step 3 101012 2110

Note − 101012 is normally written as 10101.


9.12
Simplifying Conversion in Binary
 Our digits will either be 0 or 1
 0 * anything is 0
 1 * anything is that thing
 Just add together the powers of 2 whose corresponding
digits are 1 and ignore any digits of 0

 10110 = 24 + 22 + 21 = 16 + 4 + 2 = 22
 1100001 = 26 + 25 + 20 = 64 + 32 + 1 = 97

9.13
Powers of Two

Power of Two Decimal Value

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

 Example: Convert 19 to binary


19 / 2 = 9 remainder 1
Record the remainders
9 / 2 = 4 remainder 1 and then write them
4 / 2 = 2 remainder 0 in opposite order
2 / 2 = 1 remainder 0
1 / 2 = 0 remainder 1
 19 = 100112

9.15
Decimal to Binary Conversion
Example: Convert 112 to binary

Division Remainder (R)


112 / 2 = 56 0 a0
56 / 2 = 28 0 a1
28 / 2 = 14 0 a2
14 / 2 = 7 0 a3
7/2=3 1 a4
3/2=1 1 a5
1/2=0 1 a6

• 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

 We learn the binary operations using truth tables

 Given two bits, apply the operator


 1 AND 0 = 0
 1 OR 0 = 1
 1 XOR 0 = 1
 Apply the binary (Boolean) operators bitwise (in
columns) to binary numbers as in
 10010011 AND 00001111 = 00000011 9.25
Examples
 AND – if both bits are 1 the result is 1, otherwise 0
 11111101 AND 00001111 = 00001101
 01010101 AND 10101010 = 00000000
 00001111 AND 00110011 = 00000011
 OR – if either bit is 1 the result is 1, otherwise 0
 10101010 OR 11100011 = 11101011
 01010101 OR 10101010 = 11111111
 00001111 OR 00110011 = 00111111
 NOT – flip (negate) each bit
 NOT 10101011 = 01010100
 NOT 00001111 = 11110000
 XOR – if the bits differ the result is 1, otherwise 0
 10111100 XOR 11110101 = 01001001
 11110000 XOR 00010001 = 11100001
 01010101 XOR 01011110 = 00001011 9.26
Octal Number System
 The Octal Number System is another type of computer and
digital numbering system which uses the Base-8 system.
 There are only 8 symbols or possible digit values, there are
0, 1, 2, 3, 4, 5, 6, 7.
 Each Octal number can be represented using only 3 bits,
with each group of bits having a distich values between 000
(for 0) and 111 (for 7).

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.

Decimal Number 3-bit Binary Number Octal Number


0 000 0
1 001 1
2 010 2
3 011 3
4 100 4
5 101 5
6 110 6
7 111 7
8 001 000 10 (1+0)
9 001 001 11 (1+1)
Continuing upwards in groups of three

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

 The first step is to group the binary digits in the set of 3.


 Write an octal symbol for each group underneath.
 This will give you an octal number that arrived from a binary
number.
Example – convert the binary number 1010111100 to octal
= (1010111100)2
= (001 010 111 100)2

= (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

 Decimal equivalent of any hexadecimal number 4 0100 4


5 0101 5
is sum of product of each digit with its positional 6 0110 6
value. 7 0111 7
8 1000 8
27FB16 = 2×163 + 7×162 + 15×161 + 11×160 9 1001 9

= 8192 + 1792 + 240 +11 10 1010 A


11 1011 B
= 1023510 12 1100 C
13 1101 D
14 1110 E
15 1111 F
9.36
Convert Hexadecimal to Decimal
 One way to find the decimal equivalent of a hexadecimal
number is to first convert the hexadecimal number to binary
and then convert from binary to decimal.
 Convert the hexadecimal number (1C) to decimal:

Example: Convert 1C16 to Decimal


 First: convert the hexadecimal number to binary:

1 C
0001 1100
 Second: convert the binary to decimal:

 00011100 = 24 + 2³ + 2² = 16+8+4 = 2810


 Answer: 1C16 = 2810
9.37
Numbers in Different Bases
 Good idea to memorize!
Decimal Binary Octal Hexadecimal
(Base 10) (Base 2) (Base 8) (Base 16)
00 00000 00 00
01 00001 01 01
02 00010 02 02
03 00011 03 03
04 00100 04 04
05 00101 05 05
06 00110 06 06
07 00111 07 07
08 01000 10 08
09 01001 11 09
10 01010 12 0A
11 01011 13 0B
12 01100 14 0C
13 01101 15 0D
14 01110 16 0E
15 01111 17 0F
16 10000 20 10

9.38
Binary Operations

 We learn the binary operations using truth tables

 Given two bits, apply the operator


 1 AND 0 = 0
 1 OR 0 = 1
 1 XOR 0 = 1
 Apply the binary (Boolean) operators bitwise (in
columns) to binary numbers as in
 10010011 AND 00001111 = 00000011 9.39
Examples
 AND – if both bits are 1 the result is 1, otherwise 0
 11111101 AND 00001111 = 00001101
 01010101 AND 10101010 = 00000000
 00001111 AND 00110011 = 00000011
 OR – if either bit is 1 the result is 1, otherwise 0
 10101010 OR 11100011 = 11101011
 01010101 OR 10101010 = 11111111
 00001111 OR 00110011 = 00111111
 NOT – flip (negate) each bit
 NOT 10101011 = 01010100
 NOT 00001111 = 11110000
 XOR – if the bits differ the result is 1, otherwise 0
 10111100 XOR 11110101 = 01001001
 11110000 XOR 00010001 = 11100001
 01010101 XOR 01011110 = 00001011 9.40
Binary Addition

 To add 2 bits, there are four possibilities


 0+0=0
 1+0=1
 0+1=1
 1 + 1 = 2 – we can’t write 2 in binary, but 2 is 10 in
binary, so write a 0 and carry a 1
 To compute anything useful (more than 2 single bits), we
need to add binary numbers
 This requires that we chain together carrys
 The carry out of one column becomes a carry in in the
column to its left

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:

Check your work, convert to decimal! 9.42


Binary Addition (cont’d)
 Example:
111+101 = ?

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.

 Q 1: How would you represent 10111 in the decimal


number system?
 A) 23
 B) 24
 C) 25
 D) 22

9.47
Exercises
 Convert the following binary numbers to decimal and
hexadecimal number system.
 11010101
 1110110
 00011
 100011

9.48

You might also like