Download presentation
1
The number systems of Computer Science
Binary & Hex The number systems of Computer Science
2
What you will learn Decimal Binary Hexadecimal Arithmetic
Converting between number bases Counting 2’s Compliment
3
Number Systems Prehistory Unary, or marks: / /////// = 7
/////// + ////// = ///////////// Babylonian (Mesopotamia) around 2000 BC Used 60 numerical symbols – sexadecimal. Used to measure time 5; 25, 30 = 5hr 25min 30 secs. Was positional based by had no concept of zero. 5,4560 = 5 x x 1 = 34510 Roman Numerals: (non positional, no concept of zero) VII + V = VVII = XII MCMXCIX = 1999 MCMXCVIIII = 1999 MCMLXXXXVIIII = 1999 MDCCCCLXXXXVIIII = 1999
4
Quote from Pierre Simon Laplace
“The ingenious method of expressing every possible number using a set of ten symbols (each symbol having a place value and an absolute value) emerged in India. The idea seems so simple nowadays that its significance and profound importance is no longer appreciated. Its simplicity lies in the way it facilitated calculation and placed arithmetic foremost amongst useful inventions. the importance of this invention is more readily appreciated when one considers that it was beyond the two greatest men of Antiquity, Archimedes and Apollonius. “
5
Arabic/Indian Numerals (Decimal)
Better, Arabic/Indian based Numerals: 7 + 5 = 12 = 1 x 345 is really 3 x x x 1 3 x x x 100 3 is the most significant symbol (carries the most weight) 5 is the least significant symbol (carries the least weight) Digits (or symbols) allowed: 0-9 Base (or radix): 10
6
Try multiplication in (non-positional) Roman numerals(!):
XXXIII (33 in decimal) XII (12 in decimal) XXXIII CCCXXX CCCXXXXXXXXXIIIIII CCCLXXXXVI CCCXCVI = 396 The Babylonians wouldn’t have had this problem.
7
There are many ways to “represent” a number
Representation does not affect computation result LIX + XXXIII = LXXXXII (Roman) = (Decimal) Representation affects difficulty of computing results No concept of “Zero” Computers need a representation that works with fast electronic circuits
8
What is the base ? The decimal numbering system is also known as base 10. The values of the positions are calculated by taking 10 to some power. Why is the base 10 for decimal numbers ? Because we use 10 digits. The digits 0 through 9.
9
Main Memory Original computers used holes/no hole to represent two state, 1/0. Modern computers use transistor on/off translates to values 1/0 Requires use of Binary number system
10
Binary: positional numbers work great with
2-state devices Digits (symbols) allowed: 0, 1 Binary Digits, or bits Base (radix): 2 10012 is really 1 x x X X 20 910 is really ? Computers usually multiply Arabic numerals by converting to binary, multiplying and converting back for display
11
Counting in Binary Binary 1 10 11 100 101 110 111 Decimal equivalent 1
1 10 11 100 101 110 111 Decimal equivalent 1 2 3 4 5 6 7
12
Decimal to Binary Divide decimal value by 2 until the value is 0 E.g.
47 /2 = 23 Remainder 1 23/2 = 11 Remainder 1 11/2 = 5 Remainder 1 5/2 = 2 Remainder 1 2/2 = 1 Remainder 0 1/2 = 0 Remainder 1 Read from the bottom up Ans:
13
Binary to Decimal X 20 = 1 X 21 = 0 0 X 22 = 0 20 = = X 23 = 0 21 = = X 24 = 0 22 = = X 25 = 0 23 = X 26 =
14
Binary to Decimal (alternative)
Converting the binary to 37 Multiply running total by two, add in next digit. Repeat for all digits.
15
Some buzz words Single Binary Digit =Bit 4 bits = nibble 8 bits = byte
16 bits = word 32 bits = longword 2 nibbles = 1 byte 2 bytes = 1 word The word size depends on the processor used, above is shown the word size for the 68000
16
Addition of Binary Numbers
Examples: Carry a one
17
Addition (large numbers)
Example showing larger numbers:
18
Working with large numbers
Humans can’t work well with binary numbers. We will make errors. Shorthand for binary that’s easier for us to work with - Hexadecimal
19
Hexadecimal Binary 0 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 Hex 5 0 9 7
Written:
20
What is Hexadecimal really ?
Binary Hex A number expressed in base 16. It’s easy to convert binary to hex and hex to binary because 16 is 24.
21
Counting in Hex Binary Hex Binary Hex 0 0 0 0 0 1 0 0 0 8
A B C D E F
22
Decimal to Hex Repeat dividing by 16 and noting the remainder until the quotient = 0 E.g d to Hex 54401/16 = 3400 Remainder 1 3400/16 = 212 Remainder 8 212/16 = 16 Remainder 4 13/16 = 0 Remainder 13 Remainders are expressed Hex numbers Answer: $D481
23
Hex to Decimal Write out the 1st 16 numbers
Same as for binary to decimal E.g. F9E116 1x160 = 1 Ex161 =14x16 = 224 9x =9x256 = 2304 Fx163 =15x4096= 61440 = 63969
24
Another Binary to Hex Conversion
Hex C F 7C3F16
25
Binary Coding Schemes To represent characters we use Binary Coding Schemes Two of the most popular are ASCII (American Standard Code for Information Interchange EBCDIC (Extended Binary Coded Decimal Interchange Code) Here are some ASCII codes CHARACTER ASCII A – 41 in hex B in hex C in hex D in hex BELL – 7 in hex ESC – 1B in hex
26
Binary Coded Decimal (BCD)
Each digit is converted individually to it’s binary equivalent 2634 = 3825 = Disadvantages are that arithmetic is more complicated and storage is inefficent. Used only in simple device where memory is not a problem e.g. Calculators, clocks, etc.
27
Negative Integers Most humans precede number with “-” (e.g., -2000)
Accountants, however, use parentheses: (2000) Sign-magnitude Example: in hex? = 3 x e x x 160 -3E816
28
2’s Compliment Used for negative binary numbers Procedure: E.g.
Invert all the bits: 0 becomes 1 and 1 becomes 0 Add 1 E.g. To get –1 110 = Invert all bits Add Ans: -110 =
29
2’s Compliment Using the TC notation, the Most significant indicates the sign. 1 means a negative number With 8 bits, can represent signed numbers in the range: With N bits, can represent signed numbers in the range: (2N-1)-1 0 -(2N-1) TC is widely used because it is easy to manipulate. The sign bit is treated the same as the others
30
2s Compliment Clock Stepping clockwise increases the binary number
Stepping anti-clockwise decreases the binary number Notice how when we add one to a negative number it’s values move closer to zero
31
Addition & Subtraction
Addition of TC’s numbers same as normal binary addition Subtraction of TC’s numbers can use either A-B or A + TC(B) E.g. 01112 – = ??? Change second number to TC 0111 1101+ 0100 Answer: – = 01002
32
Decimal fractions to binary
More info on p158 Clements. Question: Convert (decimal) to a binary fraction x 2 = yielding 0 0.625 x 2 = yielding 1 = yielding 0 0.5 x 2 = yielding 1 Ans:0.0101
33
Binary to Decimal fractions
More info on p158 Clements.
34
Summary Decimal Binary Hexadecimal Arithmetic
Converting between number bases Counting Coding schemes 2’s Compliment
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.