200 likes | 499 Views
Number Systems. Denary Base 10 Binary Base 2 Hexadecimal Base 16 Conversion between number systems. Signed numbers, 2’s complements binary and binary fractions. Floating point formats. Simple arithmetic operations using binary number. Bits, bytes and words. Denary Base 10.
E N D
Number Systems • Denary Base 10 • Binary Base 2 • Hexadecimal Base 16 • Conversion between number systems. • Signed numbers, 2’s complements binary and binary fractions. • Floating point formats. • Simple arithmetic operations using binary number. • Bits, bytes and words
Denary Base 10 • The base-10 system (decimal) is the most commonly used today ( 0 1 2 3 4 5 6 7 8 9) • To represent the number four thousand three hundred and twenty one (4321)
Binary Base 2 • The base-2 system (Binary) the binary system is used internally by virtually all modern computers. ( ‘0’ or ‘1’ )
Hexadecimal Base 16 • The base-16 system (Hexadecimal) uses the numerals “0 1 2 3 4 5 6 7 8 9 B C D E F” • Easy to represent binary code (form of shorthand) in which one hexadecimal digit stands in place of four binary bits. • Hex f a • Binary ,1111 1010
Converting from denary to binary • 1) Start with the number you want (44) • 2) Divide by the base you want to convert to (2) • 3) Calculate the remainder from the sum • 4) Place result of the sum on the next row • 44 denary = 101100 binary
Converting from denary to hex • 1) Start with the number you want (4321) • 2) Divide by the base you want to convert to (16) • 3) Calculate the remainder from the sum • 4) Place result of the sum on the next row • 4321 Denary = 10E1 Hexadecimal
Signed numbers • In mathematics negative numbers can be prefixed by the '-' symbol. • On a computer system several methods cane be used • Use of a sign bit • Often Most Significant bit is used for the sign • 4 Bits gives a range -7 to +7 • Two representations of '0'
1's complement • To obtain the negative number the positive binary value is complemented • '0' replaced with '1' and '1' replaced with '0' • For example binary 00001010 (decimal 10) complemented becomes 11110101
2's complement • To obtain the 2's complement of a number • First the 1's complement is obtained • Then 1 is added • i.e. decimal 10 = 00001010, complemented = 11110101 add 1 = 11110110. • Advantage of 2's complement is that no separate addition and subtraction circuits are required
Binary fractions • So far only integer numbers have been considered Whole Number Fraction • Decimal 10.75 would be 1010.11 • Limited by the number of bits assigned to whole number • Accuracy is lost smallest value is 0.00390625
Floating point numbers • In scientific applications we often need very small or large numbers • In the floating point system number is represented by a signed fractional component called the mantissa and a signed exponent. mantissa × 10exponent • The value is normalised i.e. 1230000.0 would be become 0.123×107 • In a typical system where a float is 32 bits 24 bits hold the signed mantissa and 8bits for the exponent • Floating point calculations often carried out in a separate co processor
Binary arithmetic • Binary addition
Binary arithmetic • Binary subtraction * * * * (starred columns are borrowed from) 1 1 0 1 1 1 0 − 1 0 1 1 1 ---------------- = 1 0 1 0 1 1 1
Binary arithmetic • Multiplication - Two numbers A and B can be multiplied by partial products: for each digit in B, the product of that digit in A is calculated and written on a new line, shifted leftward so that its rightmost digit lines up with the digit in B that was used. The sum of all these partial products gives the final result. 1 0 1 1 (A) (decimal 11) × 1 0 1 0 (B) (decimal 10) --------- 0 0 0 0 ← Corresponds to a zero in B + 1 0 1 1 ← Corresponds to a one in B + 0 0 0 0 + 1 0 1 1 --------------- = 1 1 0 1 1 1 0 (decimal 110)
Binary arithmetic • Division i.e. divide 0110101 (53) by 0101 (5). ___ 1010 (10 answer) 0101| 0110101 0101 110 0101 11 (3 remainder)
Bits Bytes & Words • Bit either a '1' or a '0' • Byte comprises 8 bits ' 10110011' • Nibble - Half a byte (4 bits) '1011' • Word Normally the bus width of the microprocessor – in this case 32 bits • Hex numbers in the keil compiler are prefixed by '0x' (0xa7) • Floating point numbers – exponent is represented by the letter 'e' (1.25e-3)
ASCII character codes • Integer numbers are easily represented in binary. This is not the case for characters and other punctuation marks. • The standard ASCII code defines 128 character codes (from 0 to 127), of which, the first 32 are control codes (non-printable), and the other 96 are represent printable characters. • The ASCII code requires a 7 bit binary code. Memory is usually a 8-bit wide which leaves 1 unused bit – use to provide additional characters called Extended ASCII. Not standardised!
The Standard ASCII Table * This table is organized to be easily read in hexadecimal: row numbers represent the first digit and the column numbers represent the second one. For example, the A character is located at the 4throw and the 1st column, for that it would be represented in hexadecimal as 0x41 (6510).
Unicode • ASCII only supports 128 characters • ASCII was extended to 255 characters using the iso 8859 method, where 15 regions/language groups were defined. • Unicode method contains all the worlds characters (well almost) in one coding list. • Uses multibyte encoding of 1,2 or 4 bytes • Common coding is UTF-8 • first 128 codes same as ASCII so provides backwards compatibility See http://www.unicode.org