Presentation is loading. Please wait.

Presentation is loading. Please wait.

CCE Department – Faculty of engineering - Islamic University of Lebanon Chapter 6 Binary Arithmetic.

Similar presentations


Presentation on theme: "CCE Department – Faculty of engineering - Islamic University of Lebanon Chapter 6 Binary Arithmetic."— Presentation transcript:

1 CCE Department – Faculty of engineering - Islamic University of Lebanon Chapter 6 Binary Arithmetic

2 CCE Department – Faculty of engineering - Islamic University of Lebanon Addition 1

3 CCE Department – Faculty of engineering - Islamic University of Lebanon Binary Addition Binary addition is very simple. This is best shown in an example of adding two binary numbers… 2 1 1 1 1 0 1 + 1 0 1 1 1 --------------------- 0 1 0 1 1 1111 1100 carries

4 CCE Department – Faculty of engineering - Islamic University of Lebanon Binary addition example worked out Some terms are given here Exercise: what are these numbers equivalent to in decimal? 3 1110(Carries) 1011(Augend) +1110(Addend) 11001(Sum) The initial carry in is implicitly 0 most significant bit (MSB) least significant bit (LSB)

5 CCE Department – Faculty of engineering - Islamic University of Lebanon Subtraction 4

6 CCE Department – Faculty of engineering - Islamic University of Lebanon Binary Subtraction 5 °We can also perform subtraction (with borrows in place of carries). °Let’s subtract (10111) 2 from (1001101) 2 … 1 10 0 10 10 0 0 10 1 0 0 1 1 0 1 - 1 0 1 1 1 ------------------------ 1 1 0 1 1 0 borrows

7 CCE Department – Faculty of engineering - Islamic University of Lebanon Negative Numbers 6 Subtract by adding 73 -35 38 10’s complement 73 +65 138 Ignore carry

8 CCE Department – Faculty of engineering - Islamic University of Lebanon Two’s Complement Shortcuts Algorithm – Simply complement each bit and then add 1 to the result. –Finding the 2’s complement of (01100101) 2 and of its 2’s complement… N = 01100101[N] = 10011011 10011010 01100100 + 1 + 1 --------------- 10011011 01100101 7

9 CCE Department – Faculty of engineering - Islamic University of Lebanon Negative Numbers 8 Subtract by adding 73 -35 38 73 01001001 35 00100011 2’s comp 11011100 flip +1 ----------- -35 11011101 0 1 0 0 1 0 0 1 1 1 0 1 0 0 1 0 0 1 1 0

10 CCE Department – Faculty of engineering - Islamic University of Lebanon 9

11 Signed Numbers 10 4-bit: 8H = -8 to 7H = +7 1000 to 0111 8-bit: 80H = -128 to 7F = +127 16-bit: 8000H = -32,768 to 7FFFH = +32,767 32-bit: 80000000H = -2,147,483,648 to 7FFFFFFFH = +2,147,483,647

12 CCE Department – Faculty of engineering - Islamic University of Lebanon Questions 11 What is the two’s complement of 00101100? What hex number represents the decimal number -40?

13 CCE Department – Faculty of engineering - Islamic University of Lebanon Multiplication 12

14 CCE Department – Faculty of engineering - Islamic University of Lebanon Binary Multiplication Binary multiplication is much the same as decimal multiplication, except that the multiplication operations are much simpler… 13 1 0 1 1 1 X 1 0 1 0 ----------------------- 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 1 ----------------------- 1 1 1 0 0 1 1 0

15 CCE Department – Faculty of engineering - Islamic University of Lebanon ASCII CODES 14

16 CCE Department – Faculty of engineering - Islamic University of Lebanon ASCII The most commonly used code for representing letters, numerals and punctuation characters (alphanumeric data) Each character is represented with a 7-bit string; for example: ‘3’ = 00110011 (hex 33) ‘ ’ = 00100000 (hex 20) An 8-bit extension of ASCII has also been defined 15

17 CCE Department – Faculty of engineering - Islamic University of Lebanon ASCII Code American Standard Code for Information Interchange ASCII is a 7-bit code, frequently used with an 8 th bit for error detection (more about that in a bit). 16 CharacterASCII (bin) ASCII (hex) Decimal A10000014165 B10000104266 C10000114367 … Z a … 1 ‘

18 CCE Department – Faculty of engineering - Islamic University of Lebanon ASCII Properties 17 Q1: What is relationship between a decimal digit (0, 1, …) and its ASCII code?

19 CCE Department – Faculty of engineering - Islamic University of Lebanon ASCII Properties (2) 18 Q2: What is the difference between an upper-case letter (A, B, …) and its lower-case equivalent (a, b, …)?

20 CCE Department – Faculty of engineering - Islamic University of Lebanon BCD 19

21 CCE Department – Faculty of engineering - Islamic University of Lebanon Binary Coded Decimal Binary coded decimal (BCD) represents each decimal digit with four bits –Ex. 0011 0010 1001 = 329 BCD This is NOT the same as 001100101001 2 Why do this? Because people think in decimal. 20 DigitBCD CodeDigitBCD Code 0000050101 1000160110 2001070111 3001181000 4010091001 329

22 CCE Department – Faculty of engineering - Islamic University of Lebanon Putting It All Together 21 °BCD not very efficient °Used in early computers (40s, 50s) °Used to encode numbers for seven- segment displays. °Easier to read?


Download ppt "CCE Department – Faculty of engineering - Islamic University of Lebanon Chapter 6 Binary Arithmetic."

Similar presentations


Ads by Google