You are on page 1of 39

Fundamentals Continued

Number Systems
Objectives
● Number Systems
● Number conversions
● Binary Arithmetic
● Negative Numbers
● Computer memory
● How is information stored
● Memory addressing
● Memory dimensions and size
● Types of Data
● Numeric, non-numeric and instructions
● Numeric ranges and floating point

Computing Systems
Number Systems
E.g. Octal (Base 8)
You might group things in ⭖s
What if you had ⭖ fingers ?

⭙◐◁ ⬡◤⭖ ◐ ◁
123 678
2 3

45
◻⬠
E.g. Octal (Base 8)
You might group things in ⭖s
What if you had ⭖ fingers ?

⭙◐◁ ⬡◤⭖ ◐ ?
123 678
2 0
Do we need ⭖ to mean 8?
45
We can use ⭖ to mean 0
◻⬠
0 introduced around 8th
Century (value and place
holder)
E.g. Binary (Base 2)
You might group things in 2s
Then in 2 x 2s (4s)
What if you had 2 symbols ? Then in 2 x 4s (8s)
Then in 2 x 8s (16s)

⭖⭙
⭙ ⭖ ⭖ ⭙ ⭙
01 1 0 0 1 1
Conversions between number
bases
● Subscripts are used to indicate the
base.
● e.g.
○ 0011 = 1011 ? ⟹ 001110 = 10112
○ 1234 = 4660 ? ⟹ 123416 = 466010

● They can be omitted if the base is


obvious from the context.

Computing Systems
Base subscript base

● Base subscripts are always given in


decimal
● Otherwise ⋯

To infinity and beyond


Conversions: Binary to Decimal
● This is very easy once you understand that
each “1” in a binary number adds the unique
power of 2 which corresponds with its column
position. e.g. 011012
Column 4 Column 3 Column 2 Column 1 Column 0
(sixteens) (eights) (fours) (twos) (ones)
0 1 1 0 1
0 x 24 1 x 23 1 x 22 0 x 21 1 x 20

0 + 8 + 4 + 0 + 1 = 1310

Computing Systems
Conversions - Decimal to Binary
● Work right to left and keep dividing by 2 writing down
the remainder.
● E.g. 5010
● 50 / 2 = 25 r 0 (02) LSB
● 25 / 2 = 12 r 1 (12)
● 12 / 2 = 6 r 0 (02)
● 6 / 2 = 3 r 0 (02)
● 3 / 2 = 1 r 1 (12)
● 1 / 2 = 0 r 1 (12) MSB ∴ 5010 = 1100102
● It is easy to forget the last step (bad) or just write it in
(good)

Computing Systems
Hexadecimal (Hex.) – Base 16
● Why Bother ?
● Computers like Binary
● Humans like decimal
● We just learnt to convert between the two
● So why is Hexadecimal useful ?
● Binary is cumbersome for humans to read and write
and therefore error prone
● Hexadecimal is compact to write for humans
● It is very easy to convert hex. to and from binary.

Computing Systems
First 1016 Decimal, Hex and Binary values

Decimal Hex Binary


● Learn the table to the 0 0 0000

right and you will be able 1 1 0001

to write down the 2

3
2

3
0010

0011
answer for any binary to 4 4 0100
hex or hex to binary 5 5 0101

conversion by 6 6 0110

inspection. 7 7 0111

8 8 1000
● Just work from right to 9 9 1001

left in groups of 4 binary 10 A 1010

bits or “nibbles” 11 B 1011

12 C 1100

13 D 1101

14 E 1110

15 F 1111

Computing Systems
Hexadecimal and Binary
● This last point is true for any base which is itself a power of 2.
● This is because each column “fits” a number of binary columns
● For Hex, each column can have exactly 16 possible values.
● This requires 4 binary columns which also have exactly 16 possible values
● The Hex. symbols are: 0 1 2 3 4 5 6 7 8 9 A B C D E F

Hex -> F = 1510


Binary -> 1 1 1 1
column value 23 22 21 20

1 x 23 + 1 x 22 + 1 x 21 + 1 x 20 = 1510
8 + 4 + 2 + 1 = 1510

Computing Systems
Hexadecimal and Binary

Hex -> C = 1210


Binary -> 1 1 0 0
column value 23 22 21 20

1 x 23 + 1 x 22 + 0 x 21 + 0 x 20 = 1210
8 + 4 + 0 + 0 = 1210

Computing Systems
Hex ⇔Binary example
Decimal Hex Binary

3 6 5 16
0
1
0
1
0000
0001


2 2 0010
3 3 0011
4 4 0100

11 0110 0101
5 5 0101
2 6 6 0110
7 7 0111
8 8 1000
9 9 1001

⟸ 10
11
A
B
1010
1011

● Must group right to left 12 C 1100

● Be especially careful with hex 13


14
D
E
1101
1110
numbers that look like decimal
15 F 1111

Computing Systems
Binary coded Decimal

● Unfortunately decimal is not so


cooperative
● moving into the next decimal column
does not always require a new binary
column.
9 10
1 0 0 1 ⟹ 1 0 1 0

● This is why we use hex !


Converting Decimal to Hex

● Work right to left and keep dividing by 16


and writing down the remainder.
● E.g. 250010
● 2500/16 = 156 r 4(416)
● 156/16 = 9 r 12(C16)
● 9/16 =0 r 9(916 )
● 250010 = 9C416

Computing Systems
Converting Hex to Decimal
● Similar to doing binary to decimal, this is fairly easy once you
understand the maths behind positional number systems and
have the first 16 conversion table handy and can do powers of
16; 1, 16, 256, 4096, 65536, 1048576
● E.g. Express BAD16 in base 10

column2(256s) column1(16s) column0(1s)


x 162 x 161 x 160

B16 A16 D16


1110 x 162 + 1010 x 161 + 1310 x 160

11 x 256 + 10 x 16 + 13 x 1 = 298910

Computing Systems
Computer representation of Hex

● Computers do not work well with


subscripts and various notations have
arisen to represent numbers in different
bases. For Hex the following are
common.
● #ABCD $ABCD 0xABCD

Computing Systems
Exercise

● What are the following binary in decimal?


101, 1001, 1111

● What are the following hexadecimal in


decimal?
B, 2C, 12E

Computing Systems
More exercises

● Binary <-> Hex


● 1110011 to Hex =
● B4 to binary =
● Convert Decimal to Binary
● 9, 15, 33, 64, 127, 255
● Convert Decimal to Hex
● 9, 14, 127, 269

Computing Systems
Binary Arithmetic - addition

● Example - same method as decimal


0111 = 7
+ 1100 = 12
1 0011 = 19
1 1

● What is 010 1101 + 001 0111

Computing Systems
How are negative numbers stored?

● Two’s complement
● E.g. 4 Bits
● Notice Negative all start
with 1
● Must fill all left hand bits
with 1 if –ve and using
more bits (sign extension)
● Write 2 to -3 using 8 bits

Computing Systems
Generating 2s Compliment

● Would like easy way to get from +ve


binary number to –ve (2s compliment)
● Eg decimal 7
● 4 bit representation 0111
● First take the 1s compliment
● This just means invert the bits 1000
● Now add 1 gives 1001 which is -7 in 2sC

Computing Systems
And back

● We have effectively multiplied by -1 so if


we do it again we should get back to
where we started.
● 1001 -> 1sC -> 0110 -> plus 1 -> 0111
● Questions
● What are -43 and -90 in 2’s complement
● What are 10011112sC and 10101012sC in decimal

Computing Systems
Binary Arithmetic

● 2sC was chosen because we can just


add.
● Example
0000 0011 = 3
+ 1111 1101 = -3
0000 0000 = 0
● What is 010 1101 + 101 0111

Computing Systems
Is it 2s Compliment ? Sign extension

● You need to be clear whether you are


using signed (2sC) arithmetic. The binary
pattern is the same either way
● 101 5 or -3 Must sign extend -ve e.g.
● + 010 2 or 2
4 bits
● = 111 7 or -1 1101 13 or -3
+ 0010 2 or 2
= 1111 15 or -1

Computing Systems
Computer Memory
Computer Memory
• Main memory consists of a number of storage
locations containing 1s or 0s
• One Bit stores a single 0 or 1
• 1 Byte stores 8 bits. 4 bits is called a ?
• Each location stores a word i.e. the number of
bits that can be processed in a single operation.
Word length may be typically 16, 24, 32 or as
many as 64 bits.
• The Data bus has as many “wires” as the Word
length.

Most Significant Bit (MSB) Least Significant Bit (LSB)

High-order 0 0 0 0 0 1 0 1 Low-order end


end

Computing Systems
Address Bus

● Each memory location needs a unique


address
● E.g. if we have 1610 memory locations
numbered 0 – F we need 4 bits to
address it. This implies a 4 wire address
bus.
● Memories are seldom this small.

Computing Systems
Memory Address and Data bus

● The width of the address bus determines the number


of locations that can be accessed.
● The width of the data bus is equal to the word size

H e l l o ,
Data
01001000 01100101 01101100 01101100 01101111 00101110
...
Address 00000101 0000 0110 0000 0111 0000 1000 0000 1001 0000 1010

Address Bus
Data Bus

Computing Systems
Memory Sizes

● Memory sizes
● 32 bit 232 (= 4 Gi) different memory
locations.
● 64 bit 264 (= 16 Ei )
● Questions
● What is the memory addressing capabilities
of your pc/laptop
● How much memory does it have

Computing Systems
Memory Hierarchy
● Consider : Capacity, Speed, Cost

Computing Systems
Binary and Decimal Prefixes

International Electrotechnical Commission (IEC) Prefixes


IEC prefix Representations Customary prefix
Name Symbol Base 2 Base 1024 Value Base 10 Name Symbol
kibi Ki 210 10241 1024 ≈1.02×10^3 kilo k, K
mebi Mi 220 10242 1048576 ≈1.05×10^6 mega M
gibi Gi 230 10243 1073741824 ≈1.07×10^9 giga G
tebi Ti 240 10244 1099511627776 ≈1.10×10^12 tera T
pebi Pi 250 10245 1125899906842624 ≈1.13×10^15 peta P
exbi Ei 260 10246 1152921504606846976 ≈1.15×10^18 exa E
zebi Zi 270 10247 1180591620717411303424 ≈1.18×10^21 zetta Z
yobi Yi 280 10248 1208925819614629174706176 ≈1.21×10^24 yotta Y

Computing Systems
Memory Modules

Computing Systems
Types of Data
What do these 1’s and 0’s represent?

● Numeric Data
● Integers (Signed and Unsigned)
● Decimal Numbers (Fixed and floating point)
● Non-Numeric Data
● Text, graphics, sound …
● Instructions
● Program code for the processor

Computing Systems
Storing Characters
● UTF-8 (backward compatible with ASCII)
● For coding and storing text
● Eg coding Keyboard characters
● Main encoding method for WWW
● What are ‘B’ and ‘b’ in decimal and hex
● Computer does not know the meaning of any of the
data in memory. Just a large set of ‘0’s and ‘1’s. It is
only when the context is known that the binary can be
interpreted.
● Look-up the following codes and write them in binary:
● ‘H’, ‘h’, ‘6’, ‘0’

Computing Systems
● end

Computing Systems

You might also like