Download presentation
Presentation is loading. Please wait.
Published bySolomon Watson Modified over 8 years ago
1
EEE342 Digital Electronics Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk http://www.eej.ulst.ac.uk/~ian/modules/EEE342 Lecture 2: Codes & Arithmetic
2
Binary Arithmetic - Addition So 0 0 1 1 +0+1+0 +1 ------ -- 0 1 1 10 which is ‘0’ and carry ‘1’ If you end up adding three ones then you get 11, which is a ‘1’ and a carry ‘1’ Remember to carry when you get a 2, not a ten. 0 0 0 0 1 0 1 0 1 1 1 1 0 0 1= 1401 1 0 1 1 1 0 1 0 1 1 1 0 0 0 1=+23921 +1 ------------------------------------ 0 2
3
Binary arithmetic - Subtraction 3 So 0 1 1 010 2 -0-1-0 -1-1 -1 1 ------ ---- 0 0 1can’t do so borrow ‘1’ 1 E.G 1010 = 10 10 -0101 = 5 10 ----- I.e, read this as 1 from 0 won’t go so 1 from 2 is 1 and carry 1, then we have 1 from 1 which is 0 then 1 from 0, can’t go so borrow 1. 1 from 2 is 0 and carry 1, last subtraction is 1 from 1, which is 0 1 ----- 0101 = 5 10
4
Binary Multiplication 0 0 1 1 *0*1*0 *1 ------ -- 0 0 0 1 4
5
Long Binary multiplication As for decimal, you add a zero (equivalent to shifting left one digit position, but since you only multiply by ‘1’ or by zero it becomes an addition problem 10100= 16 + 4 = 20 10 * 101= 4 + 1 = 5 10 --------- 10100 000000 1010000 ------------ = 64+32+4 = 100 10 5 1100100
6
Binary Division 6 0 0 1 1 ÷0÷1÷0 ÷1 ------ -- 0 0 0 1
7
Binary Long Division Beware the Internet! There are actually two ways of doing “division” described on the net The conventional way A simple way that gives the wrong answer BUT it is consistent. It is used in cryptography to protect binary data - a process known as adding a CRC. This is a strange thing, we will not deal with it here. In calculating CRC and other cryptographic things we throw the answer away – it is only the remainder that is used! (not on course…) COM181 Computer Hardware:IMcC7
8
For decimal long division we subtract the divisor or a multiple of it, for binary this becomes simpler, we subtract the divisor or all zeroes,. 1 0 1 0. 101 / 1 1 1 0 1 0 1 32+16+4+1= 53 1 0 1 1divide by 5 0 0 1 1 0is 10 rem 3 1 0 1 1 0 0 1 1 8 Binary Long Division
9
Two’s complement There is NO subtraction in the two’s complement system You “take the two’s complement” of a number to change its sign You then add it (to subtract it!) i.e two numbers 5 and 3. 5-3 is actually 5 + (-3) so to subtract 3 from 5, take the two’s complement of 3 and add it to 5. 9
10
in a 4 bit two’s complement system The “weights” are (-8) (+4) (+2) and (+1) Hence 5 is 0101 and 3 is 0011 (-3) is (-8)+(4)+(1) = 1101 Adding 0101= +5 1101=(-3) ------- 10010 = +2 in two’s complement we ignore bits beyond the most significant bit. COM181 Computer Hardware:IMcC10
11
Alternative way to take the two’s complement E.g to convert 3 to -3. Write 3 in binary, at the correct length (4 bits in our example here, could be bigger) 0011 NOW INVERT THE BITS 1100 THIS GIVES THIS +1 NOW ADD ONE ---- 1101 AS BEFORE. (inverting the bits is called taking the one’s complement) 11
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.