1 / 11

EEE342 Digital Electronics

EEE342 Digital Electronics. Lecture 2: Codes & Arithmetic. Ian McCrum Room 5B18, 02890366364 IJ.McCrum@ulster.ac.uk http://www.eej.ulst.ac.uk/~ian/modules/EEE342. Binary Arithmetic - Addition. So 0 0 1 1 +0 +1 +0 +1 -- -- -- -- 0 1 1 10 which is ‘0’ and carry ‘1’

march
Download Presentation

EEE342 Digital Electronics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EEE342 Digital Electronics Lecture 2:Codes & Arithmetic Ian McCrum Room 5B18, 02890366364 IJ.McCrum@ulster.ac.uk http://www.eej.ulst.ac.uk/~ian/modules/EEE342

  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

  3. Binary arithmetic - Subtraction So 0 1 1 0 10 2 -0 -1 -0 -1 -1 -1 1 -- -- -- -- -- 0 0 1 can’t do so borrow ‘1’ 1 E.G 1010 = 1010 -0101 = 510 ----- 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 1 ----- 0101 = 510

  4. Binary Multiplication 0 0 1 1 *0*1 *0*1 -- -- -- -- 0 001

  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 = 2010 * 101 = 4 + 1 = 510 --------- 10100 000000 1010000 ------------ = 64+32+4 = 10010 1100100

  6. Binary Division 0 0 1 1 ÷0 ÷1 ÷0 ÷1 -- -- -- -- 0 001

  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:IMcC

  8. Binary Long Division 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 10 1 0 1 32+16+4+1= 53 1 01 1 divide by 5 0 0 1 1 0 is 10 rem 3 1 01 1 0 0 1 1

  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.

  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) ------- 1 0010 = +2 in two’s complement we ignore bits beyond the most significant bit. COM181 Computer Hardware:IMcC

  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)

More Related