0% found this document useful (0 votes)
26 views

CS 61C Number Representation Spring 2020: 1 Unsigned Integers

This document discusses number representation in computing systems. It covers unsigned integers, signed integers using two's complement representation, and arithmetic operations on binary and hexadecimal numbers. Key points include: - Unsigned integers represent natural numbers using a radix or base, with binary using base 2, decimal base 10, and hexadecimal base 16. - Two's complement representation is used for signed integers, with the most significant bit determining the sign and addition/subtraction working the same as unsigned numbers. - Conversions between binary, decimal, and hexadecimal are demonstrated, along with computing arithmetic with overflow possibilities on 6-bit two's complement numbers. - The minimum number of bits needed to represent various value ranges is discussed,

Uploaded by

Eric Jia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

CS 61C Number Representation Spring 2020: 1 Unsigned Integers

This document discusses number representation in computing systems. It covers unsigned integers, signed integers using two's complement representation, and arithmetic operations on binary and hexadecimal numbers. Key points include: - Unsigned integers represent natural numbers using a radix or base, with binary using base 2, decimal base 10, and hexadecimal base 16. - Two's complement representation is used for signed integers, with the most significant bit determining the sign and addition/subtraction working the same as unsigned numbers. - Conversions between binary, decimal, and hexadecimal are demonstrated, along with computing arithmetic with overflow possibilities on 6-bit two's complement numbers. - The minimum number of bits needed to represent various value ranges is discussed,

Uploaded by

Eric Jia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 61C Number Representation

Spring 2020 Discussion 1: January 29th, 2020


Notes

1 Unsigned Integers
1.1 If we have an n-digit unsigned numeral dn−1 dn−2 . . . d0 in radix (or base) r, then
Pn−1
the value of that numeral is i=0 ri di , which is just fancy notation to say that
instead of a 10’s or 100’s place we have an r’s or r2 ’s place. For the three radices
binary, decimal, and hex, we just let r be 2, 10, and 16, respectively.

We don’t have calculators during exams, so let’s try this by hand. Recall that our
preferred tool for writing large numbers is the IEC prefixing system:

Ki (Kibi) = 210 Gi (Gibi) = 230 Pi (Pebi) = 250 Zi (Zebi) = 270

Mi (Mebi) = 220 Ti (Tebi) = 240 Ei (Exbi) = 260 Yi (Yobi) = 280

(a) Convert the following numbers from their initial radix into the other two
common radices:

1. 0b10010011

2. 63

3. 0b00100100

4. 0

5. 39

6. 437

7. 0x0123

(b) Convert the following numbers from hex to binary:

1. 0xD3AD

2. 0xB33F

3. 0x7EC4

(c) Write the following numbers using IEC prefixes:

• 216 • 227 • 243 • 236

• 234 • 261 • 247 • 259

(d) Write the following numbers as powers of 2:

• 2 Ki • 512 Ki • 16 Mi

• 256 Pi • 64 Gi • 128 Ei
2 Number Representation

2 Signed Integers
2.1 Unsigned binary numbers work for natural numbers, but many calculations use
negative numbers as well. To deal with this, a number of different schemes have
been used to represent signed numbers, but we will focus on two’s complement, as it
is the standard solution for representing signed integers.

• Most significant bit has a negative value, all others are positive. So the value of
Pn−2
an n-digit two’s complement number can be written as i=0 2i di − 2n−1 dn−1 .

• Otherwise exactly the same as unsigned integers.

• A neat trick for flipping the sign of a two’s complement number: flip all the
bits and add 1.

• Addition is exactly the same as with an unsigned number.

• Only one 0, and it’s located at 0b0.

For questions (a) through (c), assume an 8-bit integer and answer each one for the
case of an unsigned number, biased number with a bias of -127, and two’s complement
number. Indicate if it cannot be answered with a specific representation.

(a) What is the largest integer? What is the result of adding one to that number?

1. Unsigned?

2. Biased?

3. Two’s Complement?

(b) How would you represent the numbers 0, 1, and -1?

1. Unsigned?

2. Biased?

3. Two’s Complement?

(c) How would you represent 17 and -17?

1. Unsigned?

2. Biased?

3. Two’s Complement?

(d) What is the largest integer that can be represented by any encoding scheme
that only uses 8 bits?
Number Representation 3

(e) Prove that the two’s complement inversion trick is valid (i.e. that x and x + 1
sum to 0).

(f) Explain where each of the three radices shines and why it is preferred over
other bases in a given context.

3 Arithmetic and Counting


3.1 Addition and subtraction of binary/hex numbers can be done in a similar fashion as
with decimal digits by working right to left and carrying over extra digits to the
next place. However, sometimes this may result in an overflow if the number of bits
can no longer represent the true sum. Overflow occurs if and only if two numbers
with the same sign are added and the result has the opposite sign.

(a) Compute the decimal result of the following arithmetic expressions involving
6-bit Two’s Complement numbers as they would be calculated on a computer.
Do any of these result in an overflow? Are all these operations possible?

1. 0b011001 − 0b000111

2. 0b100011 + 0b111010

3. 0x3B + 0x06

4. 0xFF − 0xAA

(b) What is the least number of bits needed to represent the following ranges using
any number representation scheme.

1. 0 to 256

2. -7 to 56

3. 64 to 127 and -64 to -127

4. Address every byte of a 12 TiB chunk of memory

You might also like