base:numerical_systems
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:numerical_systems [2015-04-17 04:33] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Numerical systems ====== | ||
+ | ===== Preface ===== | ||
+ | |||
+ | The computers are representing physically numbers in a binary form, it is important to understand how binary numbers does work in order to do anything more serious math coding on the c64 other then basic additions/ | ||
+ | |||
+ | ===== Bits and bytes ===== | ||
+ | |||
+ | A bit is a binary digit, taking a value of either 0 or 1. For example, the number 10010111 is 8 bits long, a 8 bit long number is called a byte. | ||
+ | |||
+ | ===== Binary numbers ===== | ||
+ | |||
+ | (from wikipedia) | ||
+ | |||
+ | One can think about binary by comparing it with our usual numbers. We use a base ten system. This means that the value of each position in a numerical value can be represented by one of ten possible symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. We are all familiar with these and how the decimal system works using these ten symbols. When we begin counting values, we should start with the symbol 0, and proceed to 9 when counting. We call this the " | ||
+ | |||
+ | The " | ||
+ | < | ||
+ | 500 = (5 \times 10^2) + (0 \times 10^1) + (0 \times 10^0) | ||
+ | 5834 = (5 \times 10^3) + (8 \times 10^2) + (3 \times 10^1) + (4 \times 10^0) | ||
+ | </ | ||
+ | When we run out of symbols in the decimal numeral system, we "move to the left" one place and use a " | ||
+ | |||
+ | Binary is a base two system which works just like our decimal system, however with only two symbols which can be used to represent numerical values: 0 and 1. We begin in the " | ||
+ | |||
+ | In the binary numeral system, the value represented as 10 is (1 × 2^1) + (0 × 2^0). Thus, it equals " | ||
+ | |||
+ | Binary-to-decimal equivalence: | ||
+ | |||
+ | 1 = 1 * 2^0 = 1 * 1 => 1 | ||
+ | 10 = (1 * 2^1) + (0 * 2^0) = 2 + 0 => 2 | ||
+ | 101 = (1 * 2^2) + (0 * 2^1) + (1 * 2^0) = 4 + 0 + 1 => 5 | ||
+ | |||
+ | |||
+ | Here is another way of thinking about it: When you run out of symbols, for example 11111, add a " | ||
+ | |||
+ | ===== Hexadecimal Numbers ===== | ||
+ | |||
+ | hexadecimal, | ||
+ | |||
+ | Hexadecimal is primarily used in computing to represent a byte, whose 256 possible values can be represented with only two digits in hexadecimal notation. | ||
+ | |||
+ | Binary may be converted to and from hexadecimal easily. This is due to the fact that the radix of the hexadecimal system (16) is a power of the radix of the binary system (2). More specifically, | ||
+ | |||
+ | The following table shows each hexadecimal digit along with the equivalent decimal value and four-digit binary sequence: | ||
+ | < | ||
+ | Hex Dec Binary | ||
+ | 0 0 0000 | ||
+ | 1 1 0001 | ||
+ | 2 2 0010 | ||
+ | 3 3 0011 | ||
+ | 4 4 0100 | ||
+ | 5 5 0101 | ||
+ | 6 6 0110 | ||
+ | 7 7 0111 | ||
+ | 8 8 1000 | ||
+ | 9 9 1001 | ||
+ | A 10 1010 | ||
+ | B 11 1011 | ||
+ | C 12 1100 | ||
+ | D 13 1101 | ||
+ | E 14 1110 | ||
+ | F 15 1111 | ||
+ | </ | ||
+ | To convert a hexadecimal number into its binary equivalent, simply substitute the corresponding binary digits: | ||
+ | < | ||
+ | 3A16 = 0011 10102 | ||
+ | E716 = 1110 01112 | ||
+ | </ | ||
+ | To convert a binary number into its hexadecimal equivalent, divide it into groups of four bits. If the number of bits isn't a multiple of four, simply insert extra 0 bits at the left (called padding). For example: | ||
+ | < | ||
+ | 10100102 = 0101 0010 grouped with padding = 5216 | ||
+ | 110111012 = 1101 1101 grouped = DD16 | ||
+ | </ | ||
+ | To convert a hexadecimal number into its decimal equivalent, multiply the decimal equivalent of each hexadecimal digit by the corresponding power of 16 and add the resulting values: | ||
+ | < | ||
+ | C0E716 = (12 × 163) + (0 × 162) + (14 × 161) + (7 × 160) = (12 × 4096) + (0 × 256) + (14 × 16) + (7 × 1) = 49,38310 | ||
+ | </ |
base/numerical_systems.txt · Last modified: 2015-04-17 04:33 by 127.0.0.1