# 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
bitsinterpretation
00000
00011
00102
00113
01004
01015
01106
01117
10008
10019
101010
101111
110012
110113
111014
111115
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
bitsunsignedsigned
000000
000111
001022
001133
010044
010155
011066
011177
10008-8
10019-7
101010-6
101111-5
110012-4
110113-3
111014-2
111115-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
 a b c
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.
• 759210 = ?18