Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
List of first-order theories wikipedia , lookup
Musical notation wikipedia , lookup
Big O notation wikipedia , lookup
History of logarithms wikipedia , lookup
History of mathematical notation wikipedia , lookup
Elementary mathematics wikipedia , lookup
Location arithmetic wikipedia , lookup
Octal and Hexadecimal Representation Assuming the reader is familiar with binary notation, binary to decimal to binary conversion and binary arithmetic we consider base 8 (octal) and base 16 (hexadecimal) representations. Note that 8 and 16 are power of 2 (23 and 24 respectively) which is why they are used. Binary representation is awkward since many bits (binary digits) are needed to represent even moderately sized quantities. Octal and hexadecimal notation is more compact and as we shall see conversion between octal/hexadecimal and binary is easily done (See Grouping by Four and Grouping by Three below) The digits for octal representation are 0, 1, 2, 3, 4, 5, 6, and 7. Since 10 octal is 8 decimal, we need to go no further. There is a convention that we will follow where octal notation is denoted by a leading 0. So for example 010 is 10 base 8 while 10 is simply ten in decimal. While octal only needs the eight digits 0 thru 7, hexadecimal requires sixteen digits. So to represent that decimal quantities ten thru fifteen we use the letters A thru F. Thus the hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A (or a) for ten decimal, B (or b) for eleven, C (or c) for twelve, D (or d) for thirteen, E (or e) for fourteen and F (or f) for fifteen. Thus 10 hexadecimal is sixteen decimal. There is a convention where hexadecimal numbers are denoted by a leading 0x. So 0x10 is equal to 16 decimal. Number Conversions between Bases 2, 8 and 16 Base 10 Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Base 2 Number 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Base 8 Number 0 01 02 03 04 05 06 07 010 011 012 013 014 015 016 017 Base 16 Number 0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA 0xB 0xC 0xD 0xE 0xF From this point we will concentrate on hexadecimal notation since any technique involving hexadecimal notation is easily applied to octal. Moreover use of octal notation is not a 1 widespread as hexadecimal. Note that the contents of any byte can be represented by two hexadecimal digits. Direct Hexadecimal to Decimal Conversions The binary to decimal technique of expanding by power of 2 is easily extended to hexadecimal to decimal conversions by expanding by powers of 16. Thus 0xA2C = (10) × 16 2 + 2 × 161 + (12) × 160 = 10 × 256 + 2 × 16 + 12 × 1 = 2604 This requires knowing the powers of 16 (the powers of 2 are more easily obtained by doubling) and conversion the hexadecimal digits 0xA thru 0xF to 10 thru 15. Horner’s Method also works (?). 10 2 12 0 160 2592 ---------------16 × | 10 162 2604 + Direct Decimal to Hexadecimal Conversions Again the decimal to binary technique of subtracting powers of 2 is not so easily expended to subtracting out multiple powers of 16. 4096 256 16 1 0 ---- A ---- 2 ---- C ---- 2604 10 × 256: -2560 ---44 2 × 16: -32 ---12 12 × 12: 12 ---0 The Integer Division method for decimal to hexadecimal conversions also works except integer division by 16 is more complicated and you get remainders between 0 and 0xF. 2 Hexadecimal – Binary Conversions: Grouping by Four Every hexadecimal digit can be represented by 4 binary digits and vice versa thus making hexadecimal to binary and binary to hexadecimal conversions easy using table lookup Binary 0000 0001 0010 0011 0100 0101 0110 0111 Hexadecimal 0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 Binary 1000 1001 1010 1011 1100 1101 1110 1111 Hexadecimal 0x8 0x9 0xA 0xB 0xC 0xD 0xE 0xF Decimal – Hexadecimal Conversions This leads to an indirect approach to hexadecimal – binary conversions where a conversion is make between decimal and binary then between binary and hexadecimal Example: 0xA2C = 1010 0010 1100 (binary) = 2048 + 512 + 32 + 8 + 4 = 2604 Decimal to hexadecimal conversions reverse the process: decimal to binary then binary to hexadecimal Octal – Binary Conversions: Grouping by Three Since every octal digit can be represented by 3 binary digits and vice versa, octal binary conversions are easily done by table lookup. Binary Octal 000 0 001 01 010 02 011 03 100 04 101 05 110 06 111 07 Decimal – Octal Conversions Thus the same indirect approach introduced above can be used for octal binary conversions. Example: 2604 = 101 000 101 100 (binary) = 05054 Exercise: Can you find a simple way to convert between hexadecimal and octal? Aug 18, 2016 3