Week 2 - Binary codes Flashcards

1
Q

How do we represent unsigned numbers in binary code?

A

Unsigned binary codes are positional like the decimal system used in ordinary arithmetic.

Each digit carries a weight depending on its position in the code word.

In decimal allowed digits are 0,1,2,…,9; in binary only 1s and 0s are allowed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the base number of a positional code?

A

The position of a digit is weighted using powers of the base.

The lowest weighted digit is the least significant and the highest is the most significant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How would you break down the decimal positional code 2053 with base 10?

A

2053 with base 10 = 2x10^3 + 0x10^2 + 5 x 10^1 + 3 x 10^0

= 2000+0+50+3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you break down the binary positional code 1001 with base 2?

A

1001 with base 2 = 1x2^3 + 0x2^1 + 1x2^0

= 8+0+0+1 = 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you do decimal to binary conversion?

A

If we’re trying to convert the whole number x into binary, we need at least k bits, where k is the smallest power of 2 bigger than x.

Think: 
How many bits is it?
Write the powers for the number of bits 
Work out what can be summed to = the decmial number & put a 1 under these numbers
Then the rest should have 0s
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Convert 203 base 10 to 8-bit binary.

A

First note the largest power of 2 in 8-bit positional number is 128.

x = 203;
Is x > 128 ? If yes, write 1 and (203-128 = 75)
x = 75;
Is x>64? If yes, write 1 and (75-64 = 11)
x=11;
Is x>32? No, write 0
Is x>16? No, write 0
Is x>8? Yes, write 1 and x=11-8=3
x=3;
...
...
...
...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Add the two 4-bit numbers (unsigned binary addition)?

x=1010 and y=1111

A

11001

look at week 2, lecture slide 7 for full solution if stuck

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is 11001 base 2 in base 10?

A

25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is unsigned overflow?

A

If we add two n-bit unsigned numbers, and the sum is too big to be an n-bit number, the sum cannot be represented in the n-bit code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the necessary and sufficient condition for unsigned overflow?

A

The carry from the most significant bit (MSB) position is 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an n-bit unsigned adder?

A

An n-bit unsigned adder is a device which takes in two n-bit unsigned binary code words and outputs an n-bit number representing the sum.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a practical adder?

A

It’s an extra wire that signals whether we have a carry out and if there’s been an overflow. A practical adder should signal when there is an overflow. This can be done using the carry from the most significant bit (MSB) position. This is often referred to as the adder’s carry out (C).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is hexadecimal and why do we convert binary code words into them?

A

Binary codewords can be very long and difficult for humans to work with. We can shorten binary strings to base 16 number representation (called hexadecimal). Needs digits 0 up to 15. We use 0,1,2,3,4…,9,a,b,c,d,e,f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you turn the hex digits to 4-bit binary?

3 a 6 e

A

0011 1010 0110 1110

See week 2, video 4, 5min for more details.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the maximum number of a 16-bit unsigned code?

A

65,535

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the two’s complement code?

A

It’s an alternative to sign and magnitude, to represent signed numbers. It is the commonest codes for signed numbers.

17
Q

What are the downsides to sign and magnitude code?

A

You can have a codeword for -0

18
Q

In two’s complement code, how do you represent positive numbers for signed numbers?

A

Code words with most significant bit MSB = 0 represent positive numbers.

19
Q

In two’s complement code, how do you represent negative numbers for signed numbers?

A

To find the code word for -x, simply subtract x from 2^8 = 256 and convert the answer to binary in the usual way.

20
Q

What would 1111 1111 base 2 represent in signed and unsigned numbers?

A

signed: 255-256 = -1
unsigned: 255

21
Q

What is the largest number that an 8-bit two’s complement code can represent?

A

127
0111 1111 = 1+2+4+8+16+32+64
Since it must start with 0 to indicate that it’s positive

22
Q

How can we find the inverse of any two’s complement code number (with any number of bits)?

A

Flip all the bits (i.e. zeros to 1s and 1s to zeros) and add 1 to the result. This process is called negation

23
Q

Perform negation on 1111 1110

A

1) flip the digits of 1111 1110 (i.e. -2) to 0000 0001
2) add 1 to 0000 0001:
0000 0010 (i.e. 2)

24
Q

What is a two’s complement overflow? hint, try adding:

0000 0001 + 0111 1111 and see the output.

A

0000 0001 + 0111 1111 = 1000 0000 which = -128 in signed numbers. This is wrong. So we have a two’s complement overflow.

25
Q

How do we signal that there’s a two’s complement overflow?

A

We have a V line output. When using an adder with an unsigned code, look at C but ignore V.

26
Q

What is a character code?

A

It’s a table that maps the letters of the alphabet to a table.

27
Q

What is ASCII?

A

American Standard Code for Information Interchange. Each of the letters of the alphabet are represented in 7-bit or 8-bit code words.

28
Q

What is Unicode?

A

two-byte code, 16 bits to represent characters. It can also be extended to 32 bits.

29
Q
What do these give:
0+0
1+0
0+1
1+1
A

0+0=0, with no carry
1+0=1, with no carry
0+1=1, with no carry
1+1=0, and you carry 1.