CSE 30 -- Lecture 2 -- Sep 29
Change of base
A number N is represented in base b as a sequence of
digits di:
N = sumi=0k-1 di bi
where each of the di are allowed to take on values
between 0 and b-1 inclusive.
The addition, subtraction, multiplication, and division algorithms in
other bases are the obvious translations of the same algorithms that
we use for base 10. Integer multiplication and division by the base
corresponds to adding a trailing zero and deleting the trailing (least
significant) digit respectively. Testing for divisibility by
b-1 is done by testing the sum of all the digits in the base
b representation, just like testing for divisibility by 9 in
base 10.
We went over how to convert a base 10 number to and from another base,
as well as a fast method for converting between bases 16 and 2.
Computer Arithmetic
Numbers in computers are represented as sequences of bits. With the
usual interpretation of a sequence of binary digits, we get
non-negative numbers. For example, if we had four bits, they would be
interpreted as:
Interpreting bit strings as numbers
bits | interpretation |
0000 | 0 |
0001 | 1 |
0010 | 2 |
0011 | 3 |
0100 | 4 |
0101 | 5 |
0110 | 6 |
0111 | 7 |
1000 | 8 |
1001 | 9 |
1010 | 10 |
1011 | 11 |
1100 | 12 |
1101 | 13 |
1110 | 14 |
1111 | 15 |
and we have hardware in the ALU that would add, subtract, multiply etc
bit representations interpreted as numbers in the above manner.
To get negative numbers, we interpret the bit patterns differently but
use the same addition and subtraction hardware. We ask which numbers
when added together will give a zero result, if we ignored overflows.
When we add 1111 to 0001, we get 0000 ignoring overflows, so 1111 is
the additive inverse of 0001. Since 0001 is 1, 1111 must be -1. This
gives the following:
Multiple interpretations of bit strings as numbers
bits | unsigned | signed |
0000 | 0 | 0 |
0001 | 1 | 1 |
0010 | 2 | 2 |
0011 | 3 | 3 |
0100 | 4 | 4 |
0101 | 5 | 5 |
0110 | 6 | 6 |
0111 | 7 | 7 |
1000 | 8 | -8 |
1001 | 9 | -7 |
1010 | 10 | -6 |
1011 | 11 | -5 |
1100 | 12 | -4 |
1101 | 13 | -3 |
1110 | 14 | -2 |
1111 | 15 | -1 |
Here, the most significant bit is interpreted as the sign bit.
One Instruction Computer
The computer has 64K words and each word contains 48 bits (expressed
as 12 hexadecimal digits). The single instruction is:
subge a,b,c
which is encoded in the 48 bit word as
The instruction loaded from mem[PC] is divided into 3 fields
to extract the a,b,c values (each a 16-bit number), and
performs the following:
mem[a] = mem[a] - mem[b];
if (mem[a] >= 0) PC = c;
else PC = PC + 1;
Assignment 1
Read chapter 4.
Use the turnin program to turn in a file with answers to the
following problems. You must show your work.
where the letters A-F is used to represent 10-15 in base 16, and A-H
are used to represent 10-17 in base 18. Plain ASCII text will be
fine; you don't need to do fancy formatting. To show that a number is
written in a certain base, you can write the base in parenthesis after
the number, e.g., DEADBEEF(16). The base is expressed in base 10.
[
search CSE
| CSE home
| bsy's home page
| webster i/f
| yahoo
| hotbot
| lycos
| altavista
]
bsy+www@cs.ucsd.edu, last updated Mon Nov 30 21:53:21 PST 1998.
email bsy & tutors