程序代写代做代考 C mips algorithm go assembly computer architecture Java CSC 230: Number systems & more

CSC 230: Number systems & more
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 1

Numbers systems (and more)
• Review of basic concepts (i.e., positional number
• Conversion between bases (positive numbers)
• Some terminology involving binary numbers
• Representation of negative numbers in binary
• Canonical bit operations
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 2

Consider…
• A typical base 10 number…
7409.01
• We’ve seen this kind of number in the past • Positional notation is very familiar to us.
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 3

The “meaning” of 7409.01
0 x 10
9×1
7 x 1000
4 x 100
0 x .1
1 x .01
0 x 101
9 x 100
7 x 103 4 x 102
0x10-1 1×10-2
7409.01
the sum of…
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 4

Abstracting a little bit…
B = 10
d3=7 d2=4 d1=0 d0=9
d-1=0 d-2=1
d1 x B1
d0 x B0
d3 xB3 d2 xB2
d-1 xB-1 d-2 xB-2
7409.01
the sum of…
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 5

Weighted positional representation
d1 x B1
d0 x B0
d3 xB3 d2 xB2 d-1 xB-1 d-2 xB-2
• We can denote like this:
the sum of…
• AWnedincasntealdsowirnistete: ad write:
– where n is the number of digits
to left of the radix point
– and m is the number of digits to
right of the radix point
University of Victoria Department of Computer Science
$”%
!&'(‘ “#
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 6

Beyond base 10
• Binary (base 2)
– Digitvaluesare0and1
• Octal (base 8)
– Digitvaluesare0,1,2,3,4,5,6and7
• Hexadecimal (base 16)
– Digitvaluesare0through9,thenA,B,C,D,EandF
• Weighted positional representation formula…
– …suggestsanapproachtoconvertingfromthesethreebases into decimal
• In what follows, we’ll ignore fractional numbers
– Thisismeantosimplifyexplanations
– We’lllookatfractional&floatingpointnumberslaterinthe course
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 7

Binary
B=2
d6=1 d5=1 d4=0 d3=1 d2=0 d1=1 d0=1
d6xB6 d5xB5 d4xB4 d3xB3 d2xB2 d1xB1 d0xB0
1×64 1×32 0x16 1×8 0x4 1×2 1×1 == 107
1101011
the sum of…
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 8

Octal
B=8
d4=7 d3=2 d2=1 d1=5 d0=5
d4xB4 d3xB3 d2xB2 d1xB1 d0xB0
7×4096 2×512 1×64 5×8 5×1 == 29805
the sum of…
72155
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 9

Hexadecimal
decimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

hexadecimal (hex)
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
11

• Base 16 numbers must use additional symbols in addition to 0 through 9
– Hex digits can be either upper or lower case
– In practical terms, we try to avoid mixing cases (i.e., either use all lower-case, or all upper-case)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 10

An almost-completely-irrelevant image
Letterpress type
showing
upper-case (top)
&
lower-case (bottom)
Image: http://bit.ly/2D5tTIy
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 11

Hexadecimal
B = 16
d3=D d2=0 d1=A d0=7
d3 xB3 d2 xB2 d1 xB1 d0 xB0
13×4096 0x256 10×16 7×1 == 53415
the sum of…
D0A7
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 12

Notational conventions
• Binary numbers normally represented:
– with a prefix: 0b or %
– or with a suffix: b
• Hex numbers normally represented:
– with a prefix: 0x or $
– or with a suffix: h
• Octal numbers normally represented:
– with a prefix: 0 or 0o (“zero-oh”)
– or with a suffix: o
• Our previous three examples: 0b1101011, 072155, 0xD0A7 (or 0xd0a7)
• Decimal numbers (i.e., base 10) normally have no special prefix or suffix
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 13

Conversions
• Inourworkwewillcommonlyneedtoconvert numbers between bases
1.
2.
3.
From binary, octal, hexadecimal to decimal:
– As we have seen, this is a straightforward application of
the weighted-positional representation formula Between binary, octal, hexadecimal (i.e., from
binary to hexadecimal) – use standard shortcuts
From decimal to binary, octal or hexadecimal – use repeated division
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 14

2. Between binary, octal & hex
• From binary to octal and hexadecimal
• Take the binary sequence…
– … and starting from the right …
– … arrange into groups of three (for octal) or four (for hexadecimal)
– Finally convert each group to its corresponding digit (octal or hexadecimal)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 15

binary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
decimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
binary
octal
decimal
000
0
0
001
1
1
010
2
2
011
3
3
100
4
4
101
5
5
110
6
6
111
7
7
1000
10
8
1001
11
9
1010
12
10
1011
13
11
1100
14
12
1101
15
13



University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 16
Memorize
this
table!

Example
• A.
Convert 0b1010111000100010
A. to octal
B. to hex
To octal: groups of (up to) three binary digits starting from the right
– thatis:1010111000100010
– forwhichweuseoneoctaldigitpergroup:127042 – andfinally:0127042
To hex: groups of four binary digits starting from the right
– thatis:1010111000100010
– for which we use on hex digit per group:A E 2 2 – andfinally:0xAE22
B.
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 17

2. Between binary, octal & hex
• From octal to binary: trivial
• From hex to binary: trivial
• From octal to hex, or hex to octal:
– convert to binary
– count out binary digits from right as appropriate (in groups of three or four as needed)
– rewrite groups into appropriate digits
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 18

Do the poll!
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 19

3. Conversions from base 10 to other bases
• This is a bit more involved…
• … but still relatively straightforward
• To convert from a positive base 10 number to base B, we use the repeated division algorithm
– PerformrepeateddivisionsofbaseBintonumbertobe converted
– Eachdivisionyieldsaquotient(passedontothenextstep)…
– …andaremainder(whichisanumberfrom0uptobutnot including B) which is the next digit in the base B representation
– Digitsareproducedfromright(leastsignificant)totheleft (most significant)
– Keepdividinguntilquotientiszero
– Leadingzerosmaybeaddedtofinalresultasneeded
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 20

Example
232/8 =29 29/8 =3 3/8 =0
232%8=0 29%8=5 3%8=3
d0= 0 d1=5 d2=3
result is 0350
• Convert 232 (base 10) to octal (base 8) pass 1
pass 2
pass 3
stop
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 21

Example
35/2 =17 17/2 =8 8/2 =4 4/2 =2 2/2 =1 1/2 =0
35%2=1 d0=1 17%2=1 d1=1 8%2=0 d2=0 4%2=0 d3=0 2%2=0 d4=0 1%2=1 d5=1
result is 0b100011
• Convert 35 (base 10) to binary (base 2)
pass 1
pass 2
pass 3
pass 3
pass 4
pass 5
stop
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 22

Binary-number terminology (MIPS)
• bit: a binary digit
• special names for fixed-length bit sequences – four bits: nibble (or nybble)
– eight bits: byte
– 16 bits: half-word
– 32 bits: word
– 64 bits: double word
• least-significant bit: right-most bit • most-significant bit: left-most bit
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 23

An aside…
six multiplications
three additions
• Converting binary / octal / hex into decimal can be expensive
– equation involves to repeated use of exponentiation
• Example: ) , – . 07536=7(8)+58 +38 +68
=7∗8∗8∗8 +5∗8∗8+3∗8+6 = 3934
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 24

An aside…
• We could just pre-compute the exponentiated terms
– and keep them in a table…
– … but this is a possibly error-prone approach
• Alternative: Horner’s Algorithm
– Also called “Horner’s Method”
– Iterative algorithm used to reduce number of arithmetic operations
– uses a factored form of the positional polynomial
• Insight: equation is re-written so that higher- order terms are “deeper inside the onion”
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 25

Using polynomial evaluation…
B=8
d3=7 d2=5 d1=3 d0=6
d3 xB3 d2 xB2 d1 xB1 d0 xB0
7×512 5×64 3×8 6×1 == 3934
the sum of…
7536
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 26

Using Horner’s algorithm…
B=8
d3=7 d2=5 d1=3 d0=6
b3 = d3
b2 =d2 +b3 xB b1 =d1 +b2 xB
Answer is equal to b0
7
61
three multiplications
three additions
491
b0 =d0 +b1 xB
3934
7536
b3
b2
b1
b0
For more: http://bit.ly/2eGu7M0
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 27

Conversion summary
• Decimal ➔ binary / octal / hex:
– use repeated division algorithm
• Binary / octal / hex ➔ decimal:
– use weighted position representation equation
– also referred to as the polynomial evaluation algorithm
– Could also instead use Horner’s algorithm
• Binary / octal / hex ➔ binary / octal hex
– Either write out octal / hex digits into binary (trivial), or…
– … write binary version and group bits into groups of three or four bits
• Positive integer ➔ negative integer
– First find binary representation of positive integer
– Use change-sign rule to convert into two’s complement
– Change-sign rule also works from negative to positive
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 28

Benefits of octal and hex notation
• Althoughultimatelybitsareusedatthemost fundamental organizational level of a computer…
• …theycanbeunwieldlyasjustliterals1sand0s.
• Thereforeweusehexadecimalmoreoftento represent numbers made of bits
• Example:
– value of a byte (8 bits) can be expressed as two hex
digits (e.g., 0x81)
– value of a word can be expressed as four hex digits (e.g.,
0xFACE)
– value of a double word can be expressed as eight hex
digits (e.g., 0x55f6077c)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 29

Binary-number terminology
• byteorder(aka“endian-ness”)
– A convention on how bytes are stored in memory represent a word, double-word, etc.
– Normally we store one byte per memory address
– Assume in what follows that addr is the memory address of a byte
• big-endian
– store most-significant byte of a word in addr, least
significant byte in addr + 1 • little-endian
– store most significant byte of a word in addr + 1, least significant byte in addr
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 30

Example
0xAB
0xCD
0x98
0x76
big-endian
little-endian
0xCD
0xAB
0x76
0x98
• Two half-words stored in consecutive memory, starting at addr: 0xABCD and 0x9876
addr addr+1 addr+2 addr+3
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 31

Example
0xCA
0xFE
0xBA
0xBE
big-endian
little-endian
0xBE
0xBA
0xFE
0xCA
• A word stored in consecutive memory, starting at addr: 0xCAFEBABE
addr addr+1 addr+2 addr+3
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 32

Endian-ness
• This is always a property of the processor’s architecture
– Mainframesoriginallyusedbig-endianorder
– x86-familyarchitecturesarelittle-endian
– TheAtmelfamilyofprocessersarelittle-endian
– MIPSpermitsthechipdesignertochooseendian-ness; however, MARS implements little-endian
• Also has consequences for network communication
– big-endianorderissometimesreferredtoasnetworkbyte
order
• Some architectures also have little-endianness within a
byte
– Wewon’tworryaboutthese!
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 33

Negative number representation
• Up to this point we have:
– mostly focused on integers
– all integers considered to be positive
• Three approaches to representing negative numbers
a) signed magnitude (easy to understand)
b) one’scomplement(notsohardtounderstand) c) two’s complement (trickiest to understand)
• Before we go further, however, a wee side excursion…
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 34

Binary addition
carry 1 carry 1 carry 1
11 6
17
01011 00110+
10001
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 35

a) Signed magnitude
+12 -12 0b00001100 0b10001100
• Idea: most significant bit of binary number is reserved for sign of number
– if bit is 0, number is positive – if bit is 1, number is negative
• (Withoutsign:12=0b1100)
• When stored in a byte, must ensure we include
any necessary leading zeros
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 36

b) One’s complement
+12 -12 0b00001100 0b11110011
• Idea: negative number is the bitwise inversion of the corresponding positive number
• When stored in a byte:
– The range of numbers is from -127 to 127 – There are two ways to represent zero. Ugh.
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 37

c) Two’s complement
• Idea:negativenumberhasaspecificrelationship with both of …
– … the corresponding positive number…
– … and the number of bits stored (byte, word, double- word, etc.)
• Ignoreendiannessfornow:
– When positive: most-significant bit is always 0. – When negative: most-significant bit is always 1
• Assuming!bitsusedforstorage,anegativeinteger − # (where # is a positive number) is represented
by:
2% − #
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 38

Example (storage in byte)
+12
0b00001100
2^8 – 12 = 256 – 12 = 244
244 = 0b11110100
-12
0b11110100
2‘s complement is to 28
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 39

Example (storage in word)
+12
0b0000000000001100
2^16 – 12 = 65536– 12 = 65524
65524 = 0b1111111111110100
-12
0b1111111111110100
2‘s complement is to 216
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 40

Better way to convert into two’s complement
• We can use a modification of the one’s complement conversion help us convert a number to two’s complement
• This is done using the change-sign rule
– If the original number is indeed positive (i.e.,
leftmost bit is zero)…
– … then find the rightmost bit set to 1 …
– … and then flip all bits to the left of that bit.
• (Note: “flip” and “invert” mean the same thing)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 41

Example (12 to -12)
12 -12
00001100 11110100
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 42
Positive?
Yes!
Rightmost
bit set to 1

Recall binary addition
12 -5
7
00001100 11111011
00000111
+
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 44
overflow
carry 1
carry 1
carry 1
carry 1

Why two’s complement…?
• With two’s complement for negative numbers:
– Weneedonlyonepieceofhardwareforbothaddition
and subtraction!
• That’s not true for signed magnitude
– Wouldneedseparateadderhardwareandsubtractor hardware
• Ditto for one’s complement
• Also:
– Avoidthe“twozeros”anomalyinbothsignedmagnitudeand one’s complement
– Conversionbetweenpositiveandnegativeisveryefficient and uniform in two’s complement (i.e., no wasted bit sequences)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 45

Conversion summary
• Decimal ➔ binary / octal / hex: – userepeateddivisionalgorithm
• Binary / octal / hex ➔ decimal:
– useweightedpositionrepresentationequation
– alsoreferredtoasthepolynomialevaluationalgorithm
• Binary / octal / hex ➔ binary / octal hex
– Eitherwriteoutoctal/hexdigitsintobinary(trivial),or…
– …writebinaryversionandgroupbitsintogroupsofthreeor four bits
• Positive integer ➔ negative integer
– Firstfindbinaryrepresentationofpositiveinteger
– Usechange-signruletoconvertintotwo’scomplement – Change-signrulealsoworksfromnegativetopositive
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 46

Boolean data
• The contents of a byte may represent many things
– Abinarynumber,or…
– …Acontainerforeightindividualbits,eachpositionhaving its own meaning
• Each bit in the byte represents a boolean value – true==1== bit set
– false == 0 == bit unset
• You are already familiar with boolean operations in Java
– Theseare&&,||,!(AND,OR,NOT)
– Cannowbeappliedtoindividualbits!
– We’llalsointroduceNAND,NORandXOR
• Note: our operations will eventually be applied to all bits in a container (i.e., in a byte)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 47

Boolean operations (NOT)
a
NOT a
0
1
1
0
• The simplest
– Inverts the boolean value of a bit – also known as complement
!
!′
!”
also
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 48

Boolean operations (AND)
a
b
a AND b
0
0
0
0
1
0
1
0
0
1
1
1
• Binary operation with two operands
– Result is true only if both operands are true – Sometimes called conjunction
– Similar to meaning of “and” in English
!

also
!#”
!”
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 49

Boolean operations (OR)
a
b
a OR b
0
0
0
0
1
1
1
0
1
1
1
1
• Binary operation with two operands
– Result is true at least one operand is true – Sometimes called disjunction
– Not quite the same as “or” in English
!

!+”
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 50

Boolean operations (XOR)
a
b
a XOR b
0
0
0
0
1
1
1
0
1
1
1
0
• Binary operation with two operands
– Result is true only if exactly one operand is true
– English meaning of “or” is a mix of logical OR and XOR
!

!⨁”
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 51

Three more: NAND, NOR, XNOR
a
0
0
1
1
b
0
1
0
1
a NAND b
1
1
1
0
a
b
a NOR b
0
0
1
0
1
0
1
0
0
1
1
0
a
b
a XNOR b
0
0
1
0
1
0
1
0
0
1
1
1
!

!

!

University of Victoria Department of Computer Science
!#” !+”
!⨁”
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 52

Looking at a NOR gate…
image from an
electron microscope
(3 micron CMOS
technology)
Image: http://bit.ly/2FqEq1x
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 53

An aside… binary addition again
From: http://bit.ly/18tbODM
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 54

Looking at a NOR gate…
image from an
electron microscope
(3 micron CMOS
technology)
Image: http://bit.ly/2FqEq1x
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 55

Boolean ops
• Asmentioned,abytecanactasacontainerforeight bits
– Bit 0 is the least-significant bit
– Bit 7 is the most-significant bit
• Normallyweperformbooleanoperationsby specifying bytes as operands
– Operation is performed on the contained bits by matching bit positions in operand A and operand B
– We can use this idea to level boolean operations an implementations of other ops.
• Wecanthinkofthesebooleanopsasbeingapplied to the bit-pairs in parallel
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 56

Example: logical XOR
What is: XOR(0xE5, 0xA8)?
byte A: 0xE5
byte B: 0xA8
result: ??
111 101
00101
01000
01101
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 57
010
University of Victoria Department of Computer Science

Byte as a bit container
• … and if a byte has all eight bits set to false …
• … what is the numeric value of that byte??
• Note:
– We will leverage this fact later when coding in assembly language…
– … by performing needed boolean operations on a byte…
– … and then testing if that byte is equal to zero.
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 58

Example
• Given some byte A…
• … and a question as to whether bit 3 is set to true …
• … how could we choose a boolean operation and a byte value B …
• … to answer that question?
– (If wanted to find out of A was positive or negative, we could ask the question about bit 7, etc. etc.)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 59

Example: check for a true bit
byte A: 0b10101010 byte B: 0b00001000
This is one use of
masking
ALU
AND
University of Victoria result: 0b00001000 Department of Computer Science
CSC 230: Computer Architecture and Assembly Language
Number systems and more: Slide 60
c

Example problem
• Given some bytes A and B…
• … and the set of “days of the week” …
• … where bit 7 means Sunday, bit 6 means Monday, etc. and bit 1 means Saturday …
• … and where a bit set to true means the day is in the set …
• … how could we use boolean operations for: – set union?
– set intersection?
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 61

Example: set union
{Sunday, Monday, Tuesday}
{Tuesday, Wednesday}
byte A: 0b00110000 byte B: 0b11100000
ALU
OR
University of Victoria result: 0b11110000 Department of Computer Science
CSC 230: Computer Architecture and Assembly Language
Number systems and more: Slide 62
c

Example: set intersection
{Sunday, Monday, Tuesday}
{Tuesday, Wednesday}
byte A: 0b00110000 byte B: 0b11100000
ALU
AND
University of Victoria result: 0b00100000 Department of Computer Science
CSC 230: Computer Architecture and Assembly Language
Number systems and more: Slide 63
c

Boolean operations
• Throughoutthetermwewillseemanymoresuch problems…
– … along with interesting boolean solutions
• Wedoneedtwomoreingredients,however
• Bitshift
– bits move from left to right, or right to left
– False (that is, 0) used to fill vacated bit positions
• Bitrotate
– bits rotate from left to right (i.e., value of bit i goes to
position i-1, bit 0 goes to position n-1, etc.)…
– orrighttoleft(i.e.,valueofbitigoestopositioni+1,
bit n-1 goes to position 0, etc.)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 64

Example: shift left, shift right
byte A: 0xE5
shift original value of byte A right by 4
shift original value of byte A left by 3
111
00101
0000 0010100
1110
University of Victoria Department of Computer Science
0
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 65

Example: rotate left, rotate right
byte A: 0xE5
rotate original value of byte A right by 4
rotate original value of byte A left by 3
111
00101
1110 00101111
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 66
0101
University of Victoria Department of Computer Science

Some useful boolean operations
•a AND 0 is0: force a bit to false
• a OR 1 is 1: force a bit to true
• a XOR 1 is NOT a: used to toggle bits (i.e., flip or invert)
•a XOR a is0: reset bits
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 67

Summary
• Number representation systems
• Looked at conversion between systems
• Some conventions on describing some common bit-sequence lengths
• Negative integers as bit sequences
• Boolean operations
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Number systems and more: Slide 68