You are on page 1of 49

Chapter 1

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

One characteristic of digital system is their ability to manipulate discrete elements of information The signals in most present day electronic digital system use just two discrete values and said to be Binary A Binary Digit is called a Bit A Bit has two values: 0 or 1

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

A group of bits can be made to represent discrete symbols A digital system is a system that manipulates discrete elements of information that is represented internally in Binary format Most digital devices are programmable Digital system manipulates discrete quantities of information that are represented in binary form
University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 3

There are different base systems:


Base 2 (Binary) Base 3 Base 4 Base 5 Base 6 Base 7 Base 8 (Octal) .. Base 16 (Hexadecimal)
University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 4

Base 2: Bnary: 0, 1 Base 8: Octal: 0, 1, 2, 3, 4, 5, 6, 7 Base 10: Decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Base 16: Hexadecimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 , A, B, C, D, E, F

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

Decimal Base Binary (Base 2)


00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
University Of Sharjah

Octal (Base 8)
0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17

Hexadecimal (base 16) 16)


0 1 2 3 4 5 6 7 8 9 A B C D E F
6

Dr. Mouna Nakkar & Dr. Ali El-Moursy

A decimal number of 7,392 represents a quantity equal to 7 thousand, plus 3 hundreds, plus 9 tens, plus 2 units 7 X 103 + 3 X 102 + 9 X 101 + 2 X 100 In more general terms a5a4a3a2a1a0.a-1a-2a-3 =105 a5 + 104 a4 + 103 a3 + 102 a2 + 101 a1 + 100 a0 + 10-1 a-1 + 10-2 a-2 + 10-3 a-3
University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 7

The decimal number system is said to be of base 10 or Radix 10


Because it uses 10 digital and the coefficients are multiplied by powers of 10

The Binary system is a different number system. The coefficients of the Binary number system have only two possible values: 0 and 1. Each coefficient ai is a multiple of 2i

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

General Rules:
A number expressed in a baser system has coefficients multiplied by power of r an . rn + an-1. rn-1 + ..+ a2 . r2 + a1 . r1 + a0 + a-1. r-1 + a-2 -m 2 . r + .. + a-m . r

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

There are three major number manipulations:


1. 2. 3.

Convert from any base to decimal. Convert from decimal to any base. Convert from any base to any base.

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

10

Example,
(11010.11)2 is a binary number

Q: What is the decimal equivalent to this number? A: 24 X 1 + 23 X 1 + 22 X 0 + 21 X 1 + 20 X 0 + 2-1 X 1 + 2-2 X 1 = 26.75

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

11

Exercise:
What is the equivalent decimal number for (4021.2)5 ; a number is given in base 5

What is the equivalent decimal number for (127.4)8 ; a number given in base 8

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

12

Exercise:
What is the equivalent decimal number for (B65F)H ; a number is given in base 16

What is the equivalent decimal number for (110101)2 ; a number given in base 2

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

13

Suppose we want to convert a number in base 10 to binary or other bases. What do we do?

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

14

Converting from decimal to Binary & Octal


Steps:
1. 2.

Divide the decimal by 2 until we reach a 0 The reminder is the new binary number Reminder 1 0 0 1 0 1
Dr. Mouna Nakkar & Dr. Ali El-Moursy 15

41 2 20 2 10 2 5 2 2 2 1 2 0
University Of Sharjah

(41)d = (101001)2

Example:
Convert decimal 153 to Octal
Reminder 153 8 19 8 2 8 0 1 3 2

(153)d = (231)8

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

16

Converting a fraction Steps:


1. Multiply the Fraction by 2 2. The whole number is the new binary number

Whole Number 0.6875 X2 0.375 X2 0.750 X2 0.500 X2 0.00


University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 17

1 0 1 1

(0.6875)d = (0.1011)2

Example,
Convert (0.513)10 to Octal
Whole Number 0.513 X8 0.104 X8 0.832 X8 0.656 X8 0.248
University Of Sharjah

4 0 6 5 1
Dr. Mouna Nakkar & Dr. Ali El-Moursy 18

(0.513)d = (0.406517)8

Converting from Binary to Octal & Hex


Steps:
1.

Group the n bits of Binary and directly converting them Q: Convert the following Binary to Octal & Hex (10110001101011.111100000110)2 A: Group each three bits and find their Octal equivalence (26153.7406)8 A: Group each four bits and find their Hex equivalence (2C6B.F06)H

Example:

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

19

Converting from Octal & Hex to Decimal Steps:


1. Directly convert each bit to its Octal and Hex

equivalence

Example:
Convert the following Octal Number to its Binary (673.124)8 = (110 111 011.001010100)2 Convert the following Hex Number to its Binary (306.D)H = (0011 0000 0110. 1101)2

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

20

Determine the base of the numbers in each of the following operations:


24 + 17 = 40

14/2 =5

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

21

54/4 = 13

7 + 12 = 19

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

22

There are two types of complements for each base-r system: the radix complement and the diminished radix complement. rs complement: Radix Complement (r-1)s complement: Diminished Radix Complement

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

23

9s complement: Obtained by subtracting each digit from 9


Example:
1. 9s complement 546700 is 999999

- 546700 --------------453299 2. 9s complement 012398 is 999999 - 012398 ---------------987601

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

24

1s Complement: Obtained by Subtracting each digit from 1. Example:


1.

1s complement 1011000 is

2.

1s complement 0101101 is

1111111 - 1011000 --------------0100111 1111111 - 0101101 ------------------1010010

Simply convert each 0 to 1 and each 1 to 0


University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 25

Radix Complement:
10s complement is 9s complement +1 2s complement is 1s complement +1

Example:
10s complement of 2389 = 9999 ----------7610 1 - 2389

+ 2s complement of 1101101 is

0010010 + 1 ----------------0010011

Hint: for 2s complement, leave all significant 0s unchanged until the first 1 and then flip each 0 to 1 and each 1 to 0

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

26

Find the 10s complement of (4567)d

Find the 2s complement of (10101011)

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

27

RULE:
1. 2.

Add M to the rs complement of N M + (rn N) = M N + rn If M > N , the sum will produce an end carry, rn, which can be discarded If M < N, the sum does not produce an end carry and is equal to rn (N-M) which is the rs complement of (N M). To obtain the answer in a familiar form, take the rs complement of the sum.

3.

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

28

M N = (72532)10 (3250)10 M = 72532 N= + 96750 ----------------1 69282 - 1 00000 ------------------69282

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

29

Exercise:
Using 10s complement perform the subtraction 3250 72532

Using 2s complement perform the subtraction 1010100 - 1000011

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

30

Exercise:

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

31

There are two types of numbers:


Un-signed:
All positive quantities

Signed:
Some positive and some negative

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

32

Usually a negative numbers are represented by () minus sign In computer language this is really hard To represent a negative number assign the Most Significant Bit (MSB) to 1. If MSB is = 0, then the number is positive If MSB is = 1, then the number is negative

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

33

There are many representations for the signednumbers in binary. Most popular ones are:Signed-magnitude representation Signed-2s-complement representation

In ALL presentations MSB SHOULD be:1 for negative numbers 0 for positive numbers

In computers signed numbers are presented using signed-2s-complement format


University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 34

It is used in some ordinary arithmetic operations but not in the computer arithmetic
N bits 1 bit N-1 bits

Sign bit

Magnitude bits

Represent decimal 5 & -5 in 4-bits signedmagnitude (5)10 -> (0101)2 (-5)10 -> (1101)2
University Of Sharjah Dr. Mouna Nakkar & Dr. Ali El-Moursy 35

Decimal Base Signed Signed-2s Complement


+7 +6 +5 +4 +3 +2 +1 0 -1 -2 -3 -4 -5 -6 -7 -8
University Of Sharjah

Signed Magnitude
0111 0110 0101 0100 0011 0010 0001 0000 1001 1010 1011 1100 1101 1110 1111 ----36

0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000

Dr. Mouna Nakkar & Dr. Ali El-Moursy

Exercise:
find the decimal for the following 8-bit signed binary number in signed-2scomplement representation (10110010)2 (11110110)2 (00110010)2

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

37

Anytime we add two signed or unsigned numbers we may get an overflow.


Overflow unsigned Overflow signed

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

38

Overflow occurs when we start with n-bits and the result occupies n+1 bits. We just add another 0 to a positive number or another 1 to a negative number in the mostsignificant position to extend them to n+1 bits and then perform the addition.

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

39

If the Carry-in to the MSB (sign bit) is different than the carry-out of MSB (sign bit), then there is an overflow

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

40

Exercise: perform the following addition (signed numbers) +6 0000 0110 +13 0000 1101 --------------------+6 0000 0110 -13 1111 0011 ---------------------6 1111 1010 +13 0000 1101 ---------------------6 1111 1010 -13 1111 0011 ---------------------

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

41

An n-bit Binary Code is a group of n bits that assume 2n distinct combination If n = 2, 22 =4 distinct combinations If n = 3, 23 = 8 distinct combinations If n = 4, 24 = 16 distinct combinations

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

42

BCD Code: Binary Coded Decimal Code


BCD Digit Decimal Symbol 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
University Of Sharjah

0 1 2 3 4 5 6 7 8 9
43

Dr. Mouna Nakkar & Dr. Ali El-Moursy

ASCII Codes: American Standard Code of Information Interchange Uses seven bits to code 128 character Look book page 23

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

44

Other decimal codes Look at book page 24 table 1.7

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

45

Binary Logic is based on Binary System Holds one of two values: 0 and 1 (true, false) (yes, no)..etc Def:
Variables A,B,C, y,y,z etc. These variables can hold one of two values: 0, 1 Three basic logical operations: AND, OR, NOT

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

46

1.

2.

3.

AND: represented by . x . y = z or xy = z z = 1 if and only if both x=1 and y=1 otherwise z=0 OR: represented by + x+y=z z = 1 if either x=1 or y = 1 otherwise z=0 NOT: x = z z= 1 if x = 0 other wise z=0

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

47

Truth Table for AND, OR, and NOT

AND
x 0 0 1 1 y 0 1 0 1 xy 0 0 0 1 x 0 0 1 1

OR
y 0 1 0 1 x+y 0 1 1 1 x 0 1

NOT
x 1 0

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

48

2-input AND gate 2-input OR gate Not gate 3-input AND gate 3-input OR gate

University Of Sharjah

Dr. Mouna Nakkar & Dr. Ali El-Moursy

49

You might also like