# Boolean Arithmetic

## Binary numbers

1. Representing numbers
1. Binary to Decimal
1. Maximum value represented by k bits
1. Decimal to Binary

• 如把100转换成八进制:

• 如100转换为十六进制:

## Negative numbers

1. Possible Solution: use a sign bit

Use the left-most bit to represent the sign, -/+; Use the remaining bits to represent a positive number

Complications:

• different representation of 0 and -0
• x + (-x) != 0
• more complication
1. Two’s Complement

Represent the negative number $-x$ using the positive number $2^n - x$

1. Computing $-x$

Input: x
Output: -x (in two’s complement)
Idea:

• $2^{n} - 1 = 11111111_{2}$
• $11111111_{2} - x$ means flip all the bits of x

## Arithmetic Logic Unit

### The Hack ALU

• The ALU computes a function on the two inputs, and outputs the result
• $f$: one out of a family of pre-defined arithmetic and logical functions
• Arithmetic functions: integer addition, multiplication, division,…
• logical functions: And, Or, Xor, …
• Which functions should the ALU perform?

• two control bits

• Example

Donate article here