Presentation is loading. Please wait.

Presentation is loading. Please wait.

NUMBER SYSTEMS.

Similar presentations


Presentation on theme: "NUMBER SYSTEMS."— Presentation transcript:

1 NUMBER SYSTEMS

2 Decimal Number System Digits (or symbols) allowed: 0-9
Base (or radix) – number of unique digits = 10 The digits are usually place in positions with the digit in the most significant position having the greatest value e.g. 345 is 3 x x x 100 This means that the value of a digit in a given position is calculated by multiplying the digit by radix raised to the power of the position, where the least significant position is at position zero

3 Binary Number System Digits (symbols) allowed: 0, 1 Base (radix)= 2
Example 101 Actual value = 1 x x x 20=5 (this is the decimal system value) Get the value of 1001 Get the value of 11000 We can represent the same value using the binary number system or the decimal number system Computers represent values using the binary system while humans use the decimal system

4 Octal Number System Digits (symbols) allowed: 0-7 Base (radix)= 8
Example octal 77 Decimal Value = 781+7  80=63 Get the decimal values of the following octal numbers 10001 570 Some representations of octal numbers on code q77, Different programming languages will use different representations

5 Hexadecimal Number System
Digits (symbols) allowed: 0-9, A-F Base (radix): 16 Actual Digits 0 – 9 10-A 11-B 12-C 13-D 14-E 15-F

6 Hexadecimal Number System
E.g. Convert Hexadecimal Number AF to Decimal 10  160=175 Convert the following Hexadecimal numbers to decimal FF 9F 970 23C

7 Hexadecimal Number System
A common syntax used to represent hexadecimal values (in code) is to place the symbols "0x" as a prefix to the value. Example: 0x8D 0x430 The prefix 0x implies that the values are in hexadecimal

8 Hexadecimal Number System
A second common syntax is to place a suffix of 'h' after a value indicating that it is hexadecimal e.g. 88h, 30Fh Intel architectures do this in their assembly languages. This representation is actually more time consuming (meaning the execution time of the code) to interpret, since the entire number must be read before it can be decided what number system is being used.

9 Conversion from decimal to any other base
examples: 36 (base 10) to base 2 (binary) 36/2 = 18 r=0 -- LSB 18/2 = 9 r=0 9/2 = 4 r=1 4/2 = 2 r=0 2/2 = 1 r=0 1/2 = 0 r= MSB =100100 I.e. Divide until you have a quotient of zero The binary value is made from the remainders with the last remainder being the most significant bit and the first remainder the least significant bit

10 Conversion from decimal to any other base
38 (base 10) to base 3 38/3 = 12 r=2 <-- ls digit 12/3 = 4 r=0 4/3 = 1 r=1 1/3 = 0 r=1 <-- ms digit 38 (base 10) == 1102 (base 3) 100 (base 10) to base 5 100/5 = 20 r=0 20/5 = 4 r=0 4/5 = 0 r=4 100 (base 10) = 400 (base 5)

11 Binary to Octal Group the bits into 3's starting at least significant bit If the number of bits is not evenly divisible by 3, then add 0's at the most significant end Write 1 octal digit for each group example: (binary) = (octal) (binary) = (octal)

12 Binary to Hex Group the bits into groups of 4 bits starting at least significant symbol If the number of bits is not evenly divisible by 4, then add 0's at the most significant end Write 1 hex digit for each group example: E 1 F A 3

13 Hex to Binary Just write down the 4 bit binary code for each hexadecimal digit example: c 8

14 Octal to Binary Just write down the 3 bit binary code for each octal digit example:

15 Hex to Octal Do it in 2 steps, hex  binary  octal E.g.
FF   377

16 Octal to Hex Do it in 2 steps, octal  binary  hex E.g.
605   185

17 Binary Fractions Example: Binary Fraction to Decimal 101.001 (binary)
122 + 0 20 + 02-1+ 0 2-3 /8 5 1/8 = (decimal)

18 Decimal to Binary Fraction
Consider left and right of the decimal point separately. The number to the left can be converted to binary as before. Multiply fractional part by 2 and note the product If the product is greater than or equal to 1, then output a 1, else output a zero Multiply the fractional part of the product by 2 again Continue until the fractional part of the product is 0 or starts repeating the value of the original fractional part of the number being converted Extract the binary equivalent of the fractional part by reading from the first value output Combine the two parts to form the binary equivalent

19 Examples 7.375 = 111.011 10.25 = 1010.01 Convert the following
decimal to binary 0.625 decimal to binary binary to decimal binary to decimal

20 Decimal Fractions to Octal
7.325 = The whole part is converted in the usual way For the fractional part .325 multiply by 8, if the answer is greater than 1, output the whole part, else output a zero. Continue until the answer is zero or the original number repeats, or you have an adequate number of values after the decimal

21 Octal Fractions to Decimal
=? The whole part is converted in the usual way Using the above example the fractional part is converted as 2     8-6=7.3248 Note that because of having stopped after 6 digits in the original conversion to octal (previous slide) some accuracy is lost. The more digits after the decimal in the conversion, the more accurate the result

22 Binary Arithmetic ADDITION RULES = = = = 10 SUBSTRACTION RULES = = = = 1 or 10 – 1 =1 Addition Example =

23 Examples – subtraction
Borrow changes 0 to 1, continue changing 0s to 1s until 1 can be changed to 0 then proceed with subtraction (10111)

24 Binary Multiplication
Rules 0 x 0 = 0 0 x 1 = 0 1 x 0 = 0 1 x 1 = 1 Examples 1101 X 1100 0100 X 0011

25 Binary Division A /B = C A – dividend B – Divisor C – Quotient
Uses a series of shift and subtract operations

26 Binary Division Example

27 Binary Division Exercise 1111/1100=? 1111/10=? /10=

28 Signed Numbers Computers only deal with 0s and 1s and so we need to represent negative numbers differently from positive numbers We use sign bit to denote this (0) for positive and (1) for –ve To write -5 and -1 using binary we add a sign bit to each one. Notice that we have padded '1' with zeros so it will have four bits i.e. added an extra zero at the beginning 0101 (5) 0001 (1) To make our binary numbers negative, we simply change our sign bit from '0' to '1'. 1101 (-5) 1001 (-1)

29 Signed Numbers 4 bit Signed Number
Be sure that you do not mistake the binary number for the decimal number 1310. Since we are using 4-bit signed representation, we know the leftmost bit is our sign and the remaining three bits are our number.

30 Signed Numbers Consider the subtraction problem 3010 - 610.
We can convert this problem to an equivalent addition problem by changing 610 to -610. Now we can state the problem as; 3010 + (-610) = 2410. We can do something similar to this in binary by representing negative numbers as complements. We will look at two ways of representing signed numbers using complements:

31 1's complement Representing a signed number with 1's complement is done by changing all the bits that are 1 to 0 and all the bits that are 0 to 1. Reversing the digits in this way is also called complementing a number. For example representing -5 using 4 bits First, we write the positive value of the number in binary. 0101 (+5) Next, we reverse each bit of the number so 1's become 0's and 0's become 1's 1010 (-5)

32 Summary Binary Decimal 0111 +7 0110 +6 0101 +5 0100 +4 0011 +3 0010 +2
0001 +1 0000 +0 1111 -0 1110 -1 1101 -2 1100 -3 1011 -4 1010 -5 1001 -6 1000 -7 Summary

33 Note Whenever we use 1's complement notation, the most significant bit always tells us the sign of the number. The only exception to this rule is -0. In 1's complement, we have two ways of representing the number zero. Notice also that the values +0 to +7 are the same as the normal binary representation. Only the negative values must be complemented.

34 2’s complement Representing a signed number with 2's complement is done by adding 1 to the 1's complement representation of the number. How can we represent the number -510 in 2's complement using 4-bits? First, we write the positive value of the number in binary. 0101 (+5) Next, we reverse each bit to get the 1's complement. 1010 Last, we add 1 to the number. 1011 (-5) We notice that we only have one way to represent 0 in 2's complement. This is an advantage because it simplifies representation of signed numbers.

35 Binary Subtraction using 1’s complement
Example: 7 – 1 = 6 0111 -0001 Convert 0001 to 1’s complement 1110 Add this value to positive 7 Binary +1110 = Remove the overflow bit at the start and it to the result 0101 + 1 = – this is the answer (6 decimal

36 Binary Subtraction using 1’s complement
Exercise Use one’s complement to perform the following calculations in binary 13-9 -5-5 -20-5

37 Binary Subtraction using 2’s complement
Example: 7-1 0111 -0001 Convert 0001 to 2’s complement 1111 Add the 7 binary to -1 (2’s complement) 1111 10110 Discard the overflow bit 0110(this is the answer) In two’s complement, the overflow bit is discarded while in one’s complement, it is added back to the result

38 Binary Subtraction using 2’s complement
Exercise Use 2’s complement to perform the following calculations in binary 13-9 -5-5 -20-5

39 Data representation We have so far seen how to represent numbers
They are represented by a sequence of binary digits How do we represent characters e.g. ‘a’, ‘b’, ‘1’, ‘2’, … Note that 1 and ‘1’ are different. One is a number the other is a character The computer will represent them differently E.g. the character ‘1’ can be found in the string ‘ she was number 1’ ’22’ is a sequence of two characters i.e. the character ‘2’ and another character ‘2’. A sequence of characters is called a string

40 Data representation The set of characters recognized by computers are
Set of alphabetic characters Set of digits 0-9 Other symbols appearing on the keyboard e.g. space, ‘}’, ‘\’. ‘,’, … Some other characters are recognized by the computer. There effect can be seen but they may not visible. E.g. end of line character ‘\n’– generated when return is pressed, ‘\a’ – bell , form feed character – used to move to next page, escape character, delete character (back space). Some of these characters are used for control purposes and are known as control characters Some cannot be generated by pressing a specific character on the keyboard but have to be generated by pressing a sequence of keyboard characters e.g. by pressing the ctrl key and another character

41 Data representation The set of characters recognizable by a given computer is finite. E.g. some computers recognize 128 characters, others 256 and so forth Example: If we are using 3 bits to represent each character, then we can only have 8 unique characters i.e. 000, 001, 010, 011, 100, 101, 110, 111 For instance, this could be ‘a’ - 000, ‘b’ - 001, ‘c’- 010, ‘d’ - 011, ‘e’ - 100, ‘f’ – 101 , ‘g’- 110, ‘h’ – 111 Thus using only three bits, we cannot be able to represent many characters A character code is a mapping between binary numbers of a fixed length and the characters they represent When a character in the keyboard is pressed, a binary code corresponding to the pressed character is generated by the keyboard

42 Data representation When a character in the keyboard is pressed, a binary code corresponding to the pressed character is generated by the keyboard For instance using the code we defined in the previous slide, when ‘a’ is pressed, 000 is generated. The character code is transmitted from the keyboard to the computer a series of electrical signals that are either high or low. For ‘a’ above, 3 low pulses are transmitted Actually 5 pulses are transmitted One high pulse called start bit, The 3 low pulses for a Then one low pulse called the stop bit The start bit and the stop bit are always of opposite polarity An equal amount of time is spent is transmitting each pulse.

43 Data representation An additional pulse called the parity bit may also be transmitted Even Parity Where even parity is being used, the idea is to make the number of 1 bits even So if the number of 1 bits in the code is odd, the parity bit will have a value of 1 hence making then number of 1 bits even If the number of bits with the value 1 in the code is even, then the parity bit is set to zero, hence the number of bits remains even Odd Parity If the number of 1 bits in the code is even, the parity bit is set to 1, else it is set to zero Using even parity ‘a’ 000 – in our code will have a zero in the parity bit. Using odd parity ‘a’ in our code will have a 1 in the parity bit

44 Data representation Using even parity, the following is the pulse generated by the keyboard for the character ‘b’ 001, in our code Note that the rightmost bit is transmitted first

45 Data representation The ASCII Character Code
The character code we created with three digits is insufficient Character codes have been defined already to represent the keyboard characters Once such code is the ASCII (American standard code for Information Interchange) ASCI is used to represent a set of 128 characters using 7 bits The first 32 (0-31) characters are known as control characters which are used to send control information to the output device E.g. is the null character – 7 is the bell character – 8 is the backspace character – 13 Carriage return – brings back the printing mechanism to the left margin – Line Feed – goes to the next line

46 Data representation The ASCII Character Code
For the printable characters – 33 is ! – 48 is zero – 49 is ‘1’ is 9 65 is A 90 is Z 97 is a 122 is z Note that most computers represent characters using 8 bits When 8 bits are used to represent an ASCII characters, the leftmost bit is zero

47 Data representation Extended ASCII Character Code Uses 8 bits
Defined to include such characters as , etc. this extension enables support of 256 characters Other Representation formats UTF- 8 (universal character set transformation format) Unicode (unique, unified, universal encoding )


Download ppt "NUMBER SYSTEMS."

Similar presentations


Ads by Google