chapter 2
DESCRIPTION
nkihashfafnadhafbcsjabccTRANSCRIPT
Natural Numbers
The natural numbers can be represented on a number line as shown below.
4 + 2 = 6, again a natural number;
6 + 21 = 27, again a natural number;
22 – 6 = 16, again a natural number, but
2 – 6 is not defined in natural numbers.
Similarly, 4 × 3 = 12, again a natural number
12 × 3 = 36, again a natural number
Two natural numbers can be added and multiplied in any order and the result obtained is always same. This does not hold for subtraction and division of natural numbers.
Whole Numbers
When a natural number is subtracted from itself we can
not say what is the left out number. To remove this
difficulty, the natural numbers were extended by the
number zero (0), to get what is called the system of whole
numbers
Thus, the whole numbers are 0, 1, 2, 3, ...........
The number 0 has the following properties:
a + 0 = a = 0 + a
a – 0 = a but (0 – a) is not defined in whole numbers
a × 0 = 0 = 0 × a
Division by zero (0) is not defined.
Integers
While dealing with natural numbers and whole numbers we
found that it is not always possible to subtract a number from
another.
For example, (2 – 3), (3 – 7), (9 – 20) etc. are all not
possible in the system of natural
numbers and whole numbers. Thus, it needed another
extension of numbers which allow such subtractions.
Numeral System:-
b - numeral system base
dn - the n-th digit
n - can start from negative number if the number has a fraction part.
N+1 - the number of digits
Binary Numeral System - Base-2
Binary numbers uses only 0 and 1 digits.
B denotes binary prefix
Examples:
101012 = 10101B = 1×24+0×23+1×22+0×21+1×20
= 16+4+1= 21
101112 = 10111B = 1×24+0×23+1×22+1×21+1×20
= 16+4+2+1= 23
1000112 = 100011B =
1×25+0×24+0×23+0×22+1×21+1×20=32+2+1= 35
Decimal Numeral System - Base-10
Decimal numbers uses digits from 0..9…. These are the
regular numbers that we use.
Example:
253810 = 2×103+5×102+3×101+8×100
Conversion of binary to decimal ( base
2 to base 10)
Example: convert (1000100)2 to decimal
= 64 + 0 + 0+ 0 + 4 + 0 + 0
= (68)10
Conversion of decimal to binary ( base 10 tobase2)
Example: convert (68)10 to binary
68/¸2 = 34 remainder is 0
34/ 2 = 17 remainder is 0
17 / 2 = 8 remainder is 1
8 / 2 = 4 remainder is 0
4 / 2 = 2 remainder is 0
2 / 2 = 1 remainder is 0
1 / 2 = 0 remainder is 1
Answer = 1 0 0 0 1 0 0
Note: the answer is read from bottom (MSB) totop (LSB) as 10001002
Conversion of decimal fraction to
binary fraction
Instead of division , multiplication by 2 is carried out and the integer part of the result is saved and placed after the decimal point.
The fractional part is again multiplied by 2 and the process repeated.
Example: convert ( 0.68)10 to binary fraction.
0.68 * 2 = 1.36 integer part is 1
0.36 * 2 = 0.72 integer part is 0
0.72 * 2 = 1.44 integer part is 1
0.44 * 2 = 0.88 integer part is 0
Answer = 0. 1 0 1 0…..
Example: convert ( 68.68)10 to binary equivalent.
Answer = 1 0 0 0 1 0 0 . 1 0 1 0….
Octal Number System
Base or radix 8 number system.
1 octal digit is equivalent to 3 bits.
Octal numbers are 0 to7. (see the chart down below)
Numbers are expressed as powers of 8
Conversion of octal to decimal
( base 8 to base 10)
Example: convert (632)8 to decimal
= (6 x 82) + (3 x 81) + (2 x 80)
= (6 x 64) + (3 x 8) + (2 x 1)
= 384 + 24 + 2
= (410)10
Examples:
278 = 2×81+7×80 = 16+7 = 23
308 = 3×81+0×80 = 24
43078 = 4×83+3×82+0×81+7×80= 2247
Conversion of decimal to octal ( base
10 to base 8)
Example: convert (177)10 to octal
177 / 8 = 22 remainder is 1
22 / 8 = 2 remainder is 6
2 / 8 = 0 remainder is 2
Answer = 2 6 1
Note: the answer is read from bottom to top as(261)8, the same
as with the binary case.
Note:-Conversion of decimal fraction to octal fraction is
carried out in the same manner as decimal to binary
except that now the multiplication is carried out by 8.
Hexadecimal Number System
Base or radix 16 number system.
•1 hex digit is equivalent to 4 bits.
•Numbers are 0,1,2…..8,9, A, B, C, D, E, F.
B is 11, E is 14
Numbers are expressed as powers of 16.
160 = 1, 161 = 16, 162 = 256, 163 = 4096, 164 =65536, …
Conversion of hex to decimal ( base
16 to base10)
Example: convert (F4C)16 to decimal
= (F x 162) + (4 x 161) + (C x 160)
= (15 x 256) + (4 x 16) + (12 x 1)
Conversion of decimal to hex (base 10 to base16)
Example: convert (4768)10 to hex.
= 4768 / 16 = 298 remainder 0
= 298 / 16 = 18 remainder 10 (A)
= 18 / 16 = 1 remainder 2
= 1 / 16 = 0 remainder 1
Answer: 1 2 A 0
Conversion of binary to octal and hex
Conversion of binary numbers to octal and hex simply
requires grouping bits in the binary numbers into groups
of three bits for conversion to octal and into groups of four
bits for conversion to hex
Groups are formed beginning with the LSB and progressing
to the MSB.
Thus, 11 100 1112 = 3478
11 100 010 101 010 010 0012 = 30252218
1110 01112 = E716
11000 1010 1000 01112 = 18A8716
Decimal, Binary, Octal, and Hex
Numbers
Decimal Binary Octal Hexadecimal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Representing signed integer numbers
inside a computer
1. Sign-Magnity Representation Method
2. The two's complement encoding method
A straight forward encoding for signed numbers is
the sign-magnitude encoding method:
First bit of the data represents the sign of the integer
number
The remaining bits of the data represents the magnitude of
the integer number
Sign-Magnity Representation Method
A straight forward encoding for signed numbers is
the sign-magnitude encoding method:
First bit of the data represents the sign of the integer
number
The remaining bits of the data represents the magnitude of
the integer number
Problems with the Sign-Magnity Representation
Method
There are two different representations for ZERO
0000....0000 (+0) and
1000....0000 (-0)
The two's complement encoding
method
Modern Computers use the two's complement
encoding method to represent signed integer numbers.
2s complement presentation for positive values is same as
that used in binary number system.
2s complement representation
for negative values added to the binary
number for its absolute value is equal to
100000000.
Converting a value v to its 2's
complement code:
If value v is positive, then:
the 2's complement code is the same as its representation in the
binary number system
If value v is negative, then: First, obtain the binary number
representation x for v then do 1’s complement and then add
1 to it.
Example:
v = 7 The value is positive, so:
(1) Binary number representation is: 111
(2) 8 digit 2's complement representation is: 00000111
16 digit 2's complement representation is:
0000000000000111 and so on...
v = -7 The value is negative, so:
(1) Binary number representation for 7 is: 111
(2) 8 digit Binary number representation for 7 is:
: 00000111
(2a) 1's complement representation for 7 is:
: 11111000
(3a) 2's complement representation for -7 is:
: 11111001