0% found this document useful (0 votes)
32 views30 pages

Binary

This document provides an overview of different numbering systems and ways of representing numeric values in computing. It begins by explaining the decimal numbering system and why base 10 is commonly used. It then discusses older numbering systems like Roman, Mayan, and Babylonian before introducing binary, octal, hexadecimal, and decimal representations of numbers. Key concepts like bits, bytes, words, and endianness are defined. Algorithms for decimal and binary addition are shown. Different approaches for representing signed numbers like signed magnitude, one's complement, and two's complement are explained. Fixed-point and floating-point number representations are introduced. Finally, ASCII encoding of characters is briefly mentioned.

Uploaded by

jake
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)
32 views30 pages

Binary

This document provides an overview of different numbering systems and ways of representing numeric values in computing. It begins by explaining the decimal numbering system and why base 10 is commonly used. It then discusses older numbering systems like Roman, Mayan, and Babylonian before introducing binary, octal, hexadecimal, and decimal representations of numbers. Key concepts like bits, bytes, words, and endianness are defined. Algorithms for decimal and binary addition are shown. Different approaches for representing signed numbers like signed magnitude, one's complement, and two's complement are explained. Fixed-point and floating-point number representations are introduced. Finally, ASCII encoding of characters is briefly mentioned.

Uploaded by

jake
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/ 30

Fundamentals of Computer Systems

Binary Information

Columbia University

1/1

2/1

thinkgeek.com

The Decimal Positional Numbering System

Ten figures: 0 1 2 3 4 5 6 7 8 9
7 102 + 3 101 + 0 100 = 73010
9 102 + 9 101 + 0 100 = 99010

Why base ten?

3/1

Which Numbering System Should We Use?


Some Older Choices:
Roman: I II III IV V VI VII VIII IX X

Mayan: base 20, Shell = 0

Babylonian: base 60

4/1

Hexadecimal, Decimal, Octal, and Binary


Hex

Dec

Oct

0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
17

Bin
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111

5/1

DEC PDP-8/I, c. 1968

Binary and Octal


Oct

Bin

0
1
2
3
4
5
6
7

000
001
010
011
100
101
110
111

PC = 0 211 + 1 210 + 0 29 + 1 28 + 1 27 + 0 26 +
1 25 + 1 24 + 1 23 + 1 22 + 0 21 + 1 20
= 2 83 + 6 82 + 7 81 + 5 80
= 146910
6/1

Hexadecimal Numbers
Base 16: 0 1 2 3 4 5 6 7 8 9 A B C D E F
Instead of groups of 3 bits (octal), Hex uses groups of 4.

CAFEF00D16 = 12 167 + 10 166 + 15 165 + 14 164 +


15 163 + 0 162 + 0 161 + 13 160
= 3, 405, 705, 22910
C
A
F
E
F
0
0
D
11001010111111101111000000001101
3 1 2 7 7 5 7 0 0 1
5

Hex
Binary
Octal

7/1

Computers Rarely Manipulate True Numbers

Infinite memory still very expensive


Finite-precision numbers typical
32-bit processor: naturally manipulates 32-bit numbers
64-bit processor: naturally manipulates 64-bit numbers
How many different numbers can you
binary
octal
represent with 5
digits?
decimal
hexadecimal

8/1

Jargon
Bit

Binary digit: 0 or 1

Byte

Eight bits

Word

Natural number of bits for the processor, e.g., 16, 32, 64

LSB

Least Significant Bit (rightmost)

MSB

Most Significant Bit (leftmost)


9/1

Decimal Addition Algorithm

434
+628

4 + 8 = 12

0
1
2
3
4
5
6
7
8
9
10

0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
10 11 12

3
4
5
6
7
8
9
10
11
12
13

4
5
6
7
8
9
10
11
12
13
14

5
6
7
8
9
10
11
12
13
14
15

6
7
8
9
10
11
12
13
14
15
16

7
8
9
10
11
12
13
14
15
16
17

8
9
10
11
12
13
14
15
16
17
18

9
10
11
12
13
14
15
16
17
18
19

10 / 1

Decimal Addition Algorithm

1
434
+628
2

4 + 8 = 12
1+3+2 =

0
1
2
3
4
5
6
7
8
9
10

0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
10 11 12

3
4
5
6
7
8
9
10
11
12
13

4
5
6
7
8
9
10
11
12
13
14

5
6
7
8
9
10
11
12
13
14
15

6
7
8
9
10
11
12
13
14
15
16

7
8
9
10
11
12
13
14
15
16
17

8
9
10
11
12
13
14
15
16
17
18

9
10
11
12
13
14
15
16
17
18
19

10 / 1

Decimal Addition Algorithm

1
434
+628
62

4 + 8 = 12
1+3+2 =

4 + 6 = 10

0
1
2
3
4
5
6
7
8
9
10

0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
10 11 12

3
4
5
6
7
8
9
10
11
12
13

4
5
6
7
8
9
10
11
12
13
14

5
6
7
8
9
10
11
12
13
14
15

6
7
8
9
10
11
12
13
14
15
16

7
8
9
10
11
12
13
14
15
16
17

8
9
10
11
12
13
14
15
16
17
18

9
10
11
12
13
14
15
16
17
18
19

10 / 1

Decimal Addition Algorithm

1 1
434
+628
062

4 + 8 = 12
1+3+2 =

4 + 6 = 10

0
1
2
3
4
5
6
7
8
9
10

0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
10 11 12

3
4
5
6
7
8
9
10
11
12
13

4
5
6
7
8
9
10
11
12
13
14

5
6
7
8
9
10
11
12
13
14
15

6
7
8
9
10
11
12
13
14
15
16

7
8
9
10
11
12
13
14
15
16
17

8
9
10
11
12
13
14
15
16
17
18

9
10
11
12
13
14
15
16
17
18
19

10 / 1

Decimal Addition Algorithm

1 1
434
+628
1062

4 + 8 = 12
1+3+2 =

4 + 6 = 10

0
1
2
3
4
5
6
7
8
9
10

0 1 2
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
10 11 12

3
4
5
6
7
8
9
10
11
12
13

4
5
6
7
8
9
10
11
12
13
14

5
6
7
8
9
10
11
12
13
14
15

6
7
8
9
10
11
12
13
14
15
16

7
8
9
10
11
12
13
14
15
16
17

8
9
10
11
12
13
14
15
16
17
18

9
10
11
12
13
14
15
16
17
18
19

10 / 1

Binary Addition Algorithm

10011
+11001
+

1 + 1 = 10

0
1
10

00 01
01 10
10 11

11 / 1

Binary Addition Algorithm


1
10011
+11001
0
+

1 + 1 = 10
1 + 1 + 0 = 10

0
1
10

00 01
01 10
10 11

11 / 1

Binary Addition Algorithm


11
10011
+11001
00
+

1 + 1 = 10
1 + 1 + 0 = 10

0
1
10

00 01
01 10
10 11

1 + 0 + 0 = 01

11 / 1

Binary Addition Algorithm


011
10011
+11001
100
+

1 + 1 = 10
1 + 1 + 0 = 10

0
1
10

00 01
01 10
10 11

1 + 0 + 0 = 01
0 + 0 + 1 = 01

11 / 1

Binary Addition Algorithm


0011
10011
+11001
1100
+

1 + 1 = 10
1 + 1 + 0 = 10

0
1
10

00 01
01 10
10 11

1 + 0 + 0 = 01
0 + 0 + 1 = 01
0 + 1 + 1 = 10

11 / 1

Binary Addition Algorithm


10011
10011
+11001
101100
+

1 + 1 = 10
1 + 1 + 0 = 10

0
1
10

00 01
01 10
10 11

1 + 0 + 0 = 01
0 + 0 + 1 = 01
0 + 1 + 1 = 10

11 / 1

Signed Numbers: Dealing with Negativity

How should both positive and negative numbers be


represented?

12 / 1

Signed Magnitude Numbers


You are most familiar with this:
negative numbers have a leading
In binary, a
leading 1 means
negative:

Can be made to work, but addition is


annoying:

00002 = 0

If the signs match, add the magnitudes


and use the same sign.

00102 = 2
10102 = 2
11112 = 7

If the signs differ, subtract the smaller


number from the larger; return the
sign of the larger.

10002 = 0?

13 / 1

Ones Complement Numbers

Like Signed Magnitude, a leading 1 indicates a negative


Ones Complement number.
To negate a number, complement (flip) each bit.
00002 = 0
00102 = 2
11012 = 2
10002 = 7
11112 = 0?

Addition is nicer: just add the ones


complement numbers as if they were
normal binary.
Really annoying having a 0: two
numbers are equal if their bits are the
same or if one is 0 and the other is 0.

14 / 1

15 / 1

Twos Complement Numbers


Really neat trick: make the most
significant bit represent a negative
number instead of positive:
11012 = 8 + 4 + 1 = 3
11112 = 8 + 4 + 2 + 1 = 1
01112 = 4 + 2 + 1 = 7
10002 = 8
Easy addition: just add in binary and discard any carry.
Negation: complement each bit (as in ones
complement) then add 1.
Very good property: no 0
Twos complement numbers are equal if all their bits
are the same.
16 / 1

Number Representations Compared


Bits

Binary

Signed
Mag.

Ones
Comp.

Twos
Comp.

0000
0001
..
.

0
1

0
1

0
1

0
1

0111
1000
1001
..
.

7
8
9

7
0
1

7
7
6

7
8
7

6
7

1
0

2
1

1110
14
1111
15
Smallest number
Largest number

17 / 1

Twos Complement, In Summary

https://xkcd.com/571/

18 / 1

Fixed-point Numbers

How to represent fractional


numbers? In decimal, we continue
with negative powers of 10:
31.4159 = 3 101 + 1 100 +
4 101 + 1 102 + 5 103 + 9 104
The same trick works in binary:
1011.01102 = 1 23 + 0 22 + 1 21 + 1 20 +
0 21 + 1 22 + 1 23 + 0 24
= 8 + 2 + 1 + 0.25 + 0.125
= 11.375

19 / 1

Need a bigger range? Try Floating Point


Representation.
Floating point can represent very large numbers in a
compact way.
A lot like scientific notation, 7.776 103 , where you
have the mantissa (7.776) and exponent (3).
But for this course, think in binary: 1.10x20111
The bits of a 32-bit word are separated into fields. The
IEEE 754 standard specifies

which bits represent which fields (bit 31 is sign, bits


30-23 are 8-bit exponent, bits 22-00 are 23-bit
fraction)

how to interpret each field


20 / 1

Characters and Strings? ASCII.

21 / 1

You might also like