CS计算机代考程序代写 flex COMPSCI 210 Semester 2 – 2013

COMPSCI 210 Semester 2 – 2013

Tutorial One
Number and text Representations

1

Integer
Unsigned integer

Signed integer
Sign-magnitude
1’s complement
2’s complement

Value of a Decimal Number
Examine the decimal number “210”
We reflexively understand the value to be,

This is because,

We use 100, 10, and 1 because we are told the number is a decimal number and decimal numbers use base 10

Remember: “210” does not have a value until we calculate it

Value of a Binary Number
Now examine the binary number “101”
Since we probably don’t reflexively understand the value, we must work backwards
We use 4, 2, and 1 because we are told the number is a binary number and binary numbers use base 2

In the formula, this becomes,

Note: We usually perform our calculations using decimal numbers

Value of a 2’s Complement Number
Now examine the 2’s complement number “10001101”
2’s complement numbers include a sign bit, and negative numbers are represented by their complementary bits
This number is negative, because the leftmost bit is 1
The complement of the other bits is,

“1110011” represents a regular binary number, so,

Remember: The number is negative, so the final value is,

Exercise 1.1
Convert the following 2’s complement numbers into decimal numbers

Solution 1.1.C
“11111110”
Sign bit is 1, so this number is negative.
Calculate the 2’s complement.
Flip all the bits: 0000001
Add one. 0000010
Calculate the values of the bits.

2, but the answer is negative, so

Exercise 1.1 Solutions
1010
01011010
11111110
0011100111010011

Now we’ll solve them all using the process from the previous slide

Exercise 1.1 Solutions
1010
01011010
11111110
0011100111010011

Step 1: Identify negative numbers

Exercise 1.1 Solutions
0101
01011010
00000001
0011100111010011

Step 2: Flip the bits of negative numbers

Exercise 1.1 Solutions
0101 + 1 = 0110
01011010
00000001 + 1 = 00000010
0011100111010011

Step 3: Add one to negative numbers

Exercise 1.1 Solutions

Step 4: Split up the bits and replace each 1 by the power of 2

Exercise 1.1 Solutions

Step 5: Calculate the sum

Exercise 1.1 Solutions

Step 6: Don’t forget which numbers are negative

Decimal to Binary Conversion

Exercise 1.2
Convert the following decimal numbers into
8-bit 2’s complement binary numbers

SOLUTION 1.2.A
Decimal Value: 102
102 / 2 = 51 R 0
51 / 2 = 25 R 1
25 / 2 = 12 R 1
12 / 2 = 6 R 0
6 / 2 = 3 R 0
3 / 2 = 1 R 1
1 / 2 = 0 R 1
0 / 2 = 0 R 0

SOLUTION 1.2.A
Decimal Value: 102
102 / 2 = 51 R 0
51 / 2 = 25 R 1
25 / 2 = 12 R 1
12 / 2 = 6 R 0
6 / 2 = 3 R 0
3 / 2 = 1 R 1
1 / 2 = 0 R 1
0 / 2 = 0 R 0
0 1 1 0 0 1 1 0

Answer:

SOLUTION 1.2.D
Decimal Value: -125
125 / 2 = 62 R 1
62 / 2 = 31 R 0
31 / 2 = 15 R 1
15 / 2 = 7 R 1
7 / 2 = 3 R 1
3 / 2 = 1 R 1
1 / 2 = 0 R 1
0 / 2 = 0 R 0

SOLUTION 1.2.D
Decimal Value: -125
125 / 2 = 62 R 1
62 / 2 = 31 R 0
31 / 2 = 15 R 1
15 / 2 = 7 R 1
7 / 2 = 3 R 1
3 / 2 = 1 R 1
1 / 2 = 0 R 1
0 / 2 = 0 R 0
0 1 1 1 1 1 0 1
Calculate 2’s complement:

Answer:

Exercise 1.2 Solutions

Now we’ll solve them all using the process from the previous slides

Exercise 1.2 Solutions
0
0
1
1
1

Step 1: Divide by 2 and write down the remainder to the side

Exercise 1.2 Solutions
10
00
01
01
11

Step 2: Divide again and write the new remainder to the left

Exercise 1.2 Solutions
110
000
001
101
111

Step 3: Repeat

Exercise 1.2 Solutions
0110
0000
0001
1101
1111

Step 3: Repeat

Exercise 1.2 Solutions
00110
00000
00001
11101
11111

Step 3: Repeat

Exercise 1.2 Solutions
100110
000000
100001
111101
111111

Step 3: Repeat

Exercise 1.2 Solutions
1100110
1000000
0100001
1111101
1111111

Step 3: Repeat

Exercise 1.2 Solutions
01100110
01000000
00100001
01111101
01111111

Step 3: Repeat. When the quotient and remainder are both zero, stop.

Exercise 1.2 Solutions
01100110
01000000
00100001
10000011
01111111

Step 4: Take the 2’s complement of any negative numbers

Exercise 1.2 Solutions
102 = 01100110
64 = 01000000
33 = 00100001
-125 = 10000011
127 = 01111111

Done

Conversion Between Hex and Binary
Converting between hexadecimal and binary is easy!
Recall that hexadecimal uses the normal digits 0-9, plus the letters A-F to represent the values 10-15.
0 1 2 3 4 5 6 7 8 9 A B C D E F

Conversion Between Hex and Binary
Every hexadecimal digit can be converted into a 4 digit binary number.
Examples:

Exercise 1.3
Convert the following 2’s complement binary numbers to hexadecimal
010
10011011
0101110100010100
1111111101010001

Solution 1.3.c
0101110100010100
Split the number into groups of four, starting on the right
0101 1101 0001 0100
Calculate the hexadecimal value for each group
5 D 1 4
Write the solution with the correct sign
0x5D14 (‘0x’ is often used to indicate a hex value)

Exercise 1.3 Solutions

Now we’ll solve them all using the process from the previous slides

Exercise 1.3 Solutions

Step 1: Split into groups of 4, starting from the right

Exercise 1.3 Solutions

Step 2: Pad the leftmost group with zeros if needed

Exercise 1.3 Solutions
2
9 B
5 D 1 4
F F 5 1

Step 3: Convert each group to hex

Exercise 1.3 Solutions
0x2
0x9B
0x5D14
0xFF51

Step 4: final answer

Exercise 1.4
Convert the following hexadecimal numbers to binary
0xD
0x6E
0x8001
0xFE7F

Exercise 1.4 Solutions
0xD
0x6E
0x8001
0xFE7F

Exercise 1.4 Solutions
D
6 E
8 0 0 1
F E 7 F

Step 1: Split up the hex digits

Exercise 1.4 Solutions
1101
0110 1110
1000 0000 0000 0001
1111 1110 0111 1111

Step 2: Convert the hex digits into 4 digit binary values

Signed Complement Artihmetic
Addition
Add the numbers including the sign bits, discarding any carry out of the sign bits
Subtraction
A – B = A + (-B)
Form complement of the number that you are subtracting and do addition

0110 ( 6) 1000 (-8)
+ 0100 ( 4) + 1100 (-4)
1010 (-6) 10100 ( 4)

Overflow

Detection can be performed by examining the sign of the operands and the sum, if both operands the same but sum is different, overflow has occured

ASCII
ASCII stands for American Standard Code for Information Interchange – uses 7 bits for each character
One of many early standards for representing text in binary – became probably the most popular
It really only supported English language text, so is now outdated and superseded by Unicode
Text representations is still a large and complex topic, even with essentially one pre-dominant standard
NB: ASCII codes are still valid Unicode
In this course, will work with just ASCII for simplicity
https://www.asciitable.com/

ASCII – numbers and letters
ASCII codes are usually specified in Hex
Digits 0-9 are 0x30-0x39
How does one convert between ASCII and 2’s Complement?
Capital letters A-Z are 0x41-0x5A
Lowercase letters a-z are 0x61-0x7A
E.g. “Hi157” = 0x48 0x69 0x31 0x35 0x37

𝑨 𝑩
0 0
0 1
1 0
1 1

𝑨 𝑩
0 0 1
0 1 1
1 0 0
1 1 0

𝑨 𝑩
0 0 1 0
0 1 1 1
1 0 0 0
1 1 0 0

𝑨 𝑩
0 0 1 0 0
0 1 1 1 1
1 0 0 0 1
1 1 0 0 1

𝑨 𝑩
0 0 1 0 0
0 1 1 1 1
1 0 0 0 1
1 1 0 0 1

Decoder
Has a unique output for every combination of possible input
With input lines, there is a maximum of output lines

Ex: 2 input lines, 4 outlines
Given that the inputs and the outputs of the decoder are A(1:0) and D(3:0) respectively, what should be D if A is:

Multiplexor
Select from data or information from input
Maximum of data input lines, selection lines and only one output line
Ex: 4-to-1 Multiplexor
Given that the inputs and the outputs of the 4-to-1 multiplexor are I(3:0), S(1:0) and Y respectively, what should be Y if S is:

Write down the number of cell used if the following address is used
A[3:0] = 0010

Write down the number of cell used if the following address is used
A[3:0] = 0010

Row decoder =

Column decoder =

Row 0, Column 2
= RAM cell 2

/docProps/thumbnail.jpeg