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

Lec 1 - Number Systems and Digital Logic

13B4H = (13 x 16^3) + (11 x 16^2) + (4 x 16^1) + (0 x 16^0) = 5308 0033H = (0 x 16^1) + (3 x 16^0) = 51 5308 + 51 = 5359 = 137H So, 13B4H + 0033H = 137H
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
207 views

Lec 1 - Number Systems and Digital Logic

13B4H = (13 x 16^3) + (11 x 16^2) + (4 x 16^1) + (0 x 16^0) = 5308 0033H = (0 x 16^1) + (3 x 16^0) = 51 5308 + 51 = 5359 = 137H So, 13B4H + 0033H = 137H
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

BACS 1113

Computer
Organization and
Architecture
Number Systems and Digital
Logic

1
Chapter Overview
● The basic of number systems
○ How numbers work, the nature of counting

● Conversion between number systems


○ base 2(binary), 8 (octal), 10(decimal), 16(hex)

● Performing arithmetic operations


○ Addition, Subtraction, & multiplication

● Bitwise Logical Operations


○ AND, OR, NOT
2
Introduction

● Base/radix

Base 2 (Binary) Base 10 (Decimal)

2 digits (0,1) 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

Base 8 (Octal) Base 16 (Hexadecimal)

8 digits (0, 1, 2, 3, 4, 5, 6, 7) 16 digits (0, 1, 2, 3, 4, 5, 6, 7, 8. 9. A, B, C, D, E, F)

3
Decimal number system

The Decimal Number System uses base 10. It includes the digits {0, 1,2,…, 9}. The
weighted values for each position are:

10^4 10^3 10^2 10^1 10^0 10^-1 10^-2 10^-3

1000 1000 100 10 1 0.1 0.01 0.001


0
83 = (8 x 101) + (3 x 100)

4728 = (4 x 103) + (7 x 102) + (2 x 101) + (8 x 100) 4


Why binary system?

● Computers are made of a series of switches

● Each switch has two states: ON or OFF

● Each state can be represented by a number

○ 1 for “ON” and 0 for “OFF”

5
The Binary Number Base Systems

● Most modern computer system using binary logic. The computer represents
values(0,1) using two voltage levels (usually 0V for logic 0 and either +3.3 V
or +5V for logic 1).

● The Binary Number System uses base 2 includes only the digits 0 and 1

● The weighted values for each position are :

2^5 2^4 2^3 2^2 2^1 2^0 2^-1 2^-2


32 16 8 4 2 1 0.5 0.25
6
Binary System: Base 2
● Bit:
○ The fundamental building block of computer storage

● Digits are 1 and 0


○ 1 = true/on

○ 0 = false/off

Leftmost bit MSB LSB


● Most significant bit (MSB)
Rightmost bit 1 0 1 0 0 0 1 1
● Least significant bit (LSB)

7
Binary System: Base 2

02 = 010
To avoid confusion:
A subscript on a number used to indicate its base
12 = 110

102 = (1 x 21) + (0 x 20) = 210


112 = (1 x 21) + (1 x 20) = 310
1002 = (1 x 22) + (0 x 21) + (0 x 20) = 410
● Each digit in a binarhy number has a value depending on its position

8
Hexadecimal System: Base 16

Computer works on binary system

Example:

11110000011100001110000011100002

9
Hexadecimal System: Base 16

Binary Hex Binary Hex


A set of 4 bits is
given a symbol 0000 0 1000 8

0001 1 1001 9

0010 2 1010 A

0011 3 1011 B

0100 4 1100 C

0101 5 1101 D

0110 6 1110 E

0111 7 1111 F 10
Hexadecimal System: Base 16
Purpose:
● To solve the problems of numbers written in binary tend to be long and
difficult to express
● Conversion between binary and hex is easy
● Most computers store and manipulate data with some multiple of 4 bits
(single Hex digit)
● Example: Consider 1101111000012

1101 1110 00012 = DE116

D E 1

11
Conversion between
number systems

12
Number Base Conversion (Binary to Decimal)

Multiply each digit by its weighted position, and add each of the weighted values
together or use expansion form directly.

Example the binary value 1100 1010 represents :


1*2^7 + 1*2^6 + 0*2^5 + 0*2^4 + 1*2^3 + 0*2^2 + 1*2^1 + 0*2^0 =
1 * 128 + 1 * 64 + 0 * 32 + 0 * 16 + 1 * 8 + 0 * 4 + 1 * 2 + 0 * 1 =
128 + 64 + 0 + 0 + 8 + 0 + 2 + 0 =202

13
Example 1: Base 2 -> Base 10

1112 = (1 x 22) + (1 x 21) + (1 x 20)

=4+2+1

= 710

14
Example 2: Base 16 -> Base 10

670416 = (6 x 163) + (7 x 162) + (0 x 161) + (4 x 160)

= 24576 + 1792 + 0 + 4

= 2637210

2C16 = (2 x 161) + (C x 160)

= (2 x 161) + (12 x 160)

= 4410

15
Example 3: Base 8 -> Base 10

72638 = (7 x 83) + (2 x 82) + (6 x 81) + (3 x 80)

= 3584 + 128 + 48 + 3

= 376310

16
Example 4: Base 2 -> Base 16

1112 = 01112

= 716

1001 01002 = 9416

9 4

17
Example 5: Base 16 -> Base 2

FA1416 = 1111 1010 0001 01002

F A 1 416
11112 10102 00012 01002

18
Decimal to Binary

● Repeated Division By 2
- divide the decimal number by 2,
- If the remainder is 0, on the right side write down a 0.
- If the remainder is 1, write down a 1.

● When performing the division, the remainders which will represent the binary
equivalent of the decimal number are written beginning at the least
significant digit (right) and each new digit is written to more significant digit
(the left) of the previous digit

19
Example 6: Base 10 -> Base 2 (Division)

3510
2 35
2 17 1

2 8 1
2 4 0
1000112
2 2 0

1 0

20
Division Quotient Remainder Binary

333/2 166 1 1

166/2 83 0 01

83/2 41 1 101

Example 41/2 20 1 1101

(Decimal 20/2 10 0 01101

To 10/2 5 0 001101

5/2 2 1 1001101
Binary) 2/2 1 0 01001101

1/2 0 1 101001101

21
Example 7: Base 10 -> Base 16

815110
16 8151
16 509 710
16 31 1310 ~ D16
1FD716
16 1 1510 ~ F16
0 1

22
Aritmetic in different
Number Systems (Addition
and Multiplication)

23
Binary addition

Base 2 addition table

Example:

0 0 1 1 1

+0 +1 +0 +1 1

0 1 1 10 +1

11

24
Binary addition

Example:
Decimal Binary
109 1101101
+22 + 10110
___ __________
131 10000011
____ __________

NOTE: After addition, please check to ensure that the binary sum equals to that
decimal values you added.
25
Binary subtraction

Example:

Decimal Binary
Remaining 1 Borrowed
value after 0 2 2
12 1 1 0 0
borrowing
-9 -1 0 0 1
___ __________
3 0011
____ __________

26
Binary Multiplication
Example:
Decimal Binary

13 1 1 0 1
x5 X 1 0 1
___ __________
65 1 1 0 1
____ 0 0 0 0
1 1 0 1
____________
1 0 0 0 0 0 1
____________ 27
Hexadecimal Addition
1 3 B 4 H
Example: +0 0 3 3 H

(i) 13B4H + 0033H 1 3 E 7 H

Hint: perform calculation from right to left

● Step 1: Think of the decimal equivalent of each digit

● Step 2: Add or subtract the decimal equivalents.

● Step 3: Re-convert the decimal result to its hexadecimal

28
Hexadecimal Addition
5 3 C D H
Example:
+0 0 0 4 H
(ii) 53CDH + 0004H
5 3 D 1 H

● D + 4 = 13 + 4 = 17. Binary represenation for 17 = 0001 0001 = 11 (resulted


in a carry of one bit)

● C + 0 + 1 (carry bit from the previous sum) = 12 + 1 = 13 = D

● 3 + 0 = 3; 5 + 0 = 5
29
Hexadecimal Addition
8 7 9 7 H
Example:
(ii) 8797H + 0777H +0 7 7 7 H

8 F 0 E H
● 7+7 = 14 = E
● 9+7=16. Binary represenation for 16 = 0001 0000 = 10 (resulted in a
carry of one bit)
● 7+7+1 (carry bit from the previous sum) = 15 = F
● 8+0 = 8

30
Hexadecimal Subtraction

(i) 53CBH - 0004H

5 3 C B H

+0 2 0 4 H 11(B) - 4 = 716
5 1 C 7 H 3 - 2 = 116

31
Hexadecimal Subtraction
Remaining value after
borrowing Borrowed
(ii) C39H - B4AH
16
16
B 2
C 3 9 H

- B 4 A H 25(16+9) - 10 (A) = 1510 = F16


E F H
18 (16+2) - 4 = 1410 = E16

32
Hexadecimal Multiplication

Example: E2H x 4AH E2 x A

8 1 2 x 10 (A) = 2010 = 1416


E 2 H 10 (A) x 14 (E) = 14010 = 8C16
8C16 + 116 = 8D16
x 4 A H

8 D 4 H E2 x 4
2 x 4 = 816
3 8 8 H 14 (E) x 4 = 5610 = 3816
4 1 5 4 H

33
Bitwise Logical Operations

34
Bitwise Logical Operations: AND
Truth table
Represented by: dot,
A B A.B
A AND B = A.B / A B
F F F
Yields true if: both of its operands are true.
F T F

T F F

T T T
Digital gate diagram
35
Bitwise Logical Operations: OR
Truth table
Represented by: plus sign, v
A B A+B
A OR B = A + B / A v B
F F F
Yields true if: either/both of its operands are true.
F T T

T F T

T T T
Digital gate diagram
36
Bitwise Logical Operations: NOT
Truth table
Represented by: apostrophe, ‘
A A’
NOT A = A’ / ㄱA
F T
Inverts the value of its operand.
T F

Digital gate diagram


37
Operator Precedence

Examples
Expression Order of operations

A’ + B NOT, then OR
(A + B)’ OR, then NOT
A + (B.C) AND, then OR

38

You might also like