18
COM181 Computer Hardware Ian McCrum Room 5B18, 02890366364 [email protected] Http://www.eej.ulst.ac.uk/~ian/modules/COM181 Lecture 1: The story of ‘1’

COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 [email protected] Http://ian/modules/COM181 Lecture 1: The story of

Embed Size (px)

Citation preview

Page 1: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware

Ian McCrum Room 5B18, 02890366364

[email protected]

Http://www.eej.ulst.ac.uk/~ian/modules/COM181

Lecture 1: The story of ‘1’

Page 2: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 2

The real world

• The temperature of air – is a continuously varying value; the “value” changes over “time”

• Time is a continuously varying value as well.

• We code these into units, Celsius / Fahrenheit / Kelvin, seconds, microseconds etc.,

Page 3: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 3

• Computers must manipulate data; they take inputs, do something and produce outputs.

• Internally how do they represent the things they manipulate.

• It is easy to make devices that can hold/store/manipulate voltages, it is easier if only two voltages are allowed.

• We can describe this two values system as being a binary system

• We can use various symbols/phrases for the two values.

Computers

Page 4: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 4

Various binary symbols• True /False

• One /zero

• Active /inactive

• Current flowing in one direction or the other (+/-20uA)

• Current of one value, or a different value (4-20mA)

• Positive voltage/negative voltage (+/-12Volts)

• Presence of a voltage/ absence of a voltage (+5V / 0V )

Page 5: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 5

What is Voltage and Current• Imagine a water tank in the roofspace• You open the tap and water comes out.• The higher the tank, the higher the “pressure” or “driving force”• The wider the pipe the more flow – gallons/hour.• Pressure is “analogous” (but not identical to Voltage• Flow rate is analogous to current• Power is the product of Voltage and Current• Resistance is the ratio of Volts to amps

Note the units:• Voltage uses the symbol V and the unit Voltage (V, mV or µV)• Current uses the symbol I and the unit Amps (A, mA or µA)• Resistance uses the symbol R and the Unit Ohms (Ω, kΩ or MΩ )• Power uses the symbol P and the unit Watts (W or kW)

• Where small m stands for milli and is a 1/1000 or x 10-3

• big M stands for Mega and is a 1,000,000 or x106

• K stands for Kilo and is x 1000 or x 103

• µ stands for micro and is x 1/1,000,000 or x 10-6

<< not needed for the exam - just for interest >>

Page 6: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 6

Traditional Logic Circuit values• +5 Volts / 0Volts. – this is approximate!• Typically +4.5V and +0.4V• Guaranteed output >2.4V and <0.4V• Input recognises >2.0V and <0.8V• This allows “noise margin” of 400mV

Note:• Modern chips use less “traditional” (old) values.• 3.3V chips common, internally large chips often

reduce to 1.8V, 1.2V or less. The reason is to consume less power and go faster – but the chips are harder to make (i.e more expensive) until you have the foundry running well.

Page 7: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 7

99.999% of the time it is ok to use ‘1’ and ‘0’ or to talk about 5 volts as

a ‘1’

• How can we use ‘1’s and ‘0’s to represent real world values – such as temperature or time?

Page 8: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 8

Binary codes• Consider a number of bits as a group• Each bits position indicates its importance• Simplest is to use powers of 2 (but note it is NOT the only way)• E.g if we use 4 bit groups we have “weights” of [8 4 2 1]• So 1001 is considered as 8+1 (actually 8x1 + 4x0 + 2x0 + 1x1 )• A 4 bit binary word (sometimes called a “nibble”) can represent any

number between 0 and 15 inclusive.• Note the binary weights can also be written as x23, x22, x21, x20 and

that a 4 bit group can represent from 0 to 24-1 values (0-15 here)• An 8 bit group is called a byte and can hold 0-255 values (0 - 28-1)• A 16 bit group CAN be called a word – 0-65535 values• Technically a word is the base size of the registers within a machine.

A machine with 32 bit registers has a word size of 32 bits which can hold numbers of about 4 billion

Page 9: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 9

Natural Binary – the 8421 weights

• We can convert binary to decimal by just adding up the weights

• To convert decimal to binary we can successively divide by two and note the remainder.

E.g 1110 11/2 = 5 remainder 1

5/2 = 2 remainder 1

2/2 = 1 remainder 0

1/2 = 0 remainder 1 so 1110 is 10112

Page 10: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 10

Conventions• 11012 can also be written as b’1101’ Some

software tools accepts this as an input• 4 bits can be replaced by a single symbol, we

can’t just use numbers as we need 16. The HEX convention allows use of 0-9 and then ‘A’, ‘B’, ‘C’, ‘D’, ‘E’ and ‘F’

• Many software tools use a prefix of 0x

• So 0xC is 12 in decimal or 11002 in binary

• Of most use in large binary numbers – too errorprone to write down as b’11011010101010101010111101110101’

Page 11: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 11

HEX numbers• b’11011010101010101010111101110101’• To convert binary to hex, split the binary up in 4 bit nibbles. NB

always start at the rightmost bit, the least significant bit b0

• Add leading zeros so that you are dealing with a multiple of 4, not needed here as the example is a 32 bit number.

• 1101 1010 1010 1010 1010 1111 0111 0101• Use a lookup table to convert each nibble to a single symbol• 1101 1010 1010 1010 1010 1111 0111 0101• D A A A A F 7 5• Collect the symbols together and prefix with 0x• The HEX representation of this number is 0xDAAAAF75

• This way of showing you HEX implies it is just a way of saving ink – just a way of conveniently working with binary. Alternatively you can treat HEX numbers as BASE-16 numbers the same way we used BASE 2 numbers with binary

0000 = 00001 = 10010 = 20011 = 30100 = 40101 = 50110 = 60111 = 71000 = 81001 = 91010 = A1011 = B1100 = C1101 = D1110 = E1111 = F

Page 12: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 12

• To convert 0x247E to decimal• Treat the weights as x163, x162, x161, x160

• (if you do a lot of these you end up remembering that the weights are x4096, x256, x16 and x1.)

• 4 hex digits can represent 16 bits, 0-65535• 4 hex digits can represent 0 to 164-1• 32 bit binary numbers require 8 hex digits.

HEX numbers

Page 13: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 13

Coding numbers in ‘1’s and ‘0’s• Irrespective of whether we write down hex

or binary, the computer stores ‘1’s and ‘0’s• Given an arbitrary binary number we need

to know what it is representing.• Some (old)calculators uses 8421 codes

but do not allow codes above 1001.• Some (old)caluclators use a 2421 code• There is also an excess-3 code in use.

Page 14: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 14

Uses for binary numbers• You can use binary numbers to represent positive whole numbers.• You can use “natural binary” or any weighted binary code• You can use a subset of the available codes e.g 10 out of 16 - This is

“Binary Coded Decimal” also called BCD, this suits humans...

• Positive and negative numbers (2 conventions are in common use)

• The tones on a piano! (i.e anything)

• Floating point numbers (a couple of conventions exist)

• Character codes (usually 7 or 8 bit ASCII codes or unicode – up to 16 bits )

I.E you must know the convention that is being used if you want to make sense of a binary number. Do not assume it is just natural binary.

Page 15: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 15

Positive and Negative binary• One method suits humans, one suits chips• If we set aside a single bit out of the binary word (usually the

leftmost bit). We can use it as a “sign” bit where a ‘1’ means ‘-’ and a ‘0’ means ‘+’ This is called “Signed Binary”

• So 1101 might mean [1] 101 = -5

• We can change the sign of the left most weight. • So for 4 bits we’d use (x -8),(x4),(x2),(x1). • So 1101 = (-8) + (4) +(1) = -3.• This method is called “Two’s Complement”• Calculating the equivalent decimal value by using the sign of the

leftmost bit is not the only way. An alternative is to convert the binary number to its “ones complement” and add 1.

• Hence 1101 has a ones complement of 0010 and by adding 1 we get 0011 which is +3 for the twos complement of the 1101. Taking the two’s complement is the equivalent of changing the sign so the original number must have been -3

Page 16: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 16

Floating Point numbers• As humans, we are used to fractions such as 12.75• In the binary world we can design our own conventions. i.e code 1275 into

16 bits and assume there is a implied “binary point” in the middle. This would be BCD

• Or extend the binary system to use weights of ½ , ¼ , 1/8 This might mean some loss of precision. (we can code 12.75 exactly into our extended weighted natural binary. 1100.110 ) but we could not do 12.80

• The scientific notation 2.4 x 103 can also be encoded in binary. There is an IEEE standard for this (IEEE754)(although some others exist as well) Basically we “normalise” and encode the mantissa and exponent into fixed size fields.

• When you normalise a binary number it will always begin with a ‘1’ so we can leave it out!

• The 32 bit IEEE standard reserves one bit for the sign, 8 bits for the exponent and 23 bits for a representation of the mantissa (without its leading ‘1’) the exponent is stored with a bias of +127 and can be in the range -126 to +127 to fit in the 8 bits. Zero and other “special numbers” can use codes at the extremities of the allowable range.

Page 17: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 17

ASCII codes for characters

Copied from http://en.wikipedia.org/wiki/File:ASCII_Code_Chart.svg

So the 8 bit HEX code 0x47 is the ASCII character ‘G’

Page 18: COM181 Computer Hardware Ian McCrumRoom 5B18, 02890366364 IJ.McCrum@ulster.ac.uk Http://ian/modules/COM181 Lecture 1: The story of

COM181 Computer Hardware:IMcC 18

Summary• Be able to convert Binary, hex and decimal to and from each others

representations

• Be able to convert signed and 2’s complement numbers to other representations

• Be able to convert fractions and scientific notations to and from decimal

• Be able to work out the hex or binary codes for characters using ASCII