Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2: Operations Bryan Burlingame 9Sept2015.

Similar presentations


Presentation on theme: "Lecture 2: Operations Bryan Burlingame 9Sept2015."— Presentation transcript:

1 Lecture 2: Operations Bryan Burlingame 9Sept2015

2 Announcements Homework posted Homework 1 due next week Bring headphones to lab E-mail: bryan.burlingame@me30.orgbryan.burlingame@me30.org Still do not have Canvas access For Lab, turn in a hard copy

3 Recall binary Base 2 number system Mimics the actual hardware computers are built upon Two values, 0 and 1 01111000 2 to decimal 2 6 + 2 5 + 2 4 + 2 3 = 120

4 Binary to Hexadecimal Hexadecimal (base 16) is a convenient numbering system  0 – 9, A – F (A = 10 10, B = 11 10, etc Observe 2 4 = 16, allows four bits (a nyble) to be grouped 1100 2 = 12 10 = 0xC 16

5 Binary to Hexadecimal Convert Binary to Hex 1100001110011111b

6 Binary to Hexadecimal Convert Binary to Hex 1100 0011 1001 1111 b (grouping 4 bits) 12 3 9 15 d C 3 9 F h

7 Hex to Decimal C39Fh 12 * 16 3 + 3 * 16 2 + 9 * 16 1 + 15 * 16 0 = 50,079 CharacterValue F15 E14 D13 C12 B11 A10 0 – 90 - 9

8 Decimal to binary Many ways, this is how I do it 120  120 < 128, 0 in 7 th position  120 > 64, 1 in 6 th position 120 – 64 = 56  56 > 32, 1 in 5 th position 56 – 32 = 24  24 > 16, 1 in 4 th position 24 – 16 = 8  8 = 8, 1 in 3 rd position 8 – 8 = 0  Once we hit zero, all other values are zero  0111 1000 Why do I do it this way? It is quick when I don’t have a calculator. Your mileage may vary BinaryDecimal 11 102 1004 10008 1000016 10000032 100000064 10000000128

9 Representations Decimal (default)BinaryHexadecimal 1080’011011000x6C 108d0110 1100b6Ch 108 10 0110 1100 2 6C 16 108 dec0110 1100 bin6C hex Group by 3s with a comma Group by 4s with a space or an underbar Generally don’t group Spoken short form

10 Bitwise arithmetic Mimics digital hardware Based on Boolean logic Operates on each bit within a number  (i.e. operates bitwise) Many, many hardware peripherals take advantage of bitwise operations Implemented directly in hardware  Very fast

11 Binary (Bitwise) And - & &01 000 101 Y X 194 & 225 = 227 1100 0010 (194) & 1110 0001 (225) -------------------------------- 1100 0000 (192) Binary And is commonly used with “bitmasks” A binary & used with a bitmask can ensure that a given bit is turned “off” & is shift + 7

12 Binary (Bitwise) Or - | |01 001 111 Y X 194 | 225 = 227 1100 0010 (194) | 1110 0001 (225) -------------------------------- 1110 0011 (227) Binary OR, is, also, commonly used with “bitmasks” A binary | used with a bitmask can ensure that a given bit is turned “on” | is shift + \

13 Binary (Bitwise) Xor - ⊕ ⊕ 01 001 110 Y X 194 ^ 225 = 35 1100 0010 (194) ⊕ 1110 0001 (225) -------------------------------- 0010 0011 (35) Xors are commonly used to switch the values of selected bits or to test for inequivalence C uses ^ for Xor ^ is shift + 6

14 Bitshifts ( > Right Shift) A bit shift shifts bits in a direction Left shift shifts bits to the left and simulates a multiply of 2 Right shift shifts bits to the right and simulates an integer division of 2 Bits outside the range are lost 23 << 3 = 184 (left shift by 3) 0001 0111 shifted = 1011 1000 23 >> 2 = 5 (right shift by 2) 0000 0101 = 5 (note the last two bits are lost)

15 True and False Generally, false is zero and true is not- zero Usually, all comparisons which are true generate a 1 (23 > 4) = 1 This comes up a lot!

16 Modulo Division (%) Integer division which provides the “remainder” from an integer division Assuming integer operations  123 % 6 = 3  123 / 6 = 20 (note, the fractional portion will be dropped) Recall: False is 0, and True is not 0  What does X % 2 give for all odd numbers?

17 Order of operations – C & Matlab Operators * / %Multiplication, division, modulo (integer) division + -Addition, subtraction >Left bitshift, right bitshift &Bitwise and ^Bitwise xor |Bitwise or

18 References Nicholas, P. (1994). Digital Design. Minneapolis/St. Paul: West Publishing Company


Download ppt "Lecture 2: Operations Bryan Burlingame 9Sept2015."

Similar presentations


Ads by Google