Scorpio News |
October–December 1987 – Volume 1. Issue 4. |
Page 17 of 55 |
---|
For those of you who, like me, left school with Maths ‘O’ level or alternatively finished school a long time ago (or both), here is a quick refresher. The notation that I shall use to represent powers is borrowed from Microsoft MBASIC. e.g. ten squared will be shown as 10^2 while ten cubed will be shown as 10^3.
Consider the following:
Decimal | Binary | Equivalent | ||||||
---|---|---|---|---|---|---|---|---|
1 | = | 10^0 | 1 | = | 2^0 | = | 1 | |
10 | = | 10^1 | 10 | = | 2^1 | = | 2 | |
100 | = | 10^2 | 100 | = | 2^2 | = | 4 | |
1000 | = | 10^3 | 1000 | = | 2^3 | = | 8 | |
10000 | = | 10^4 | 10000 | = | 2^4 | = | 16 | |
100000 | = | 10^5 | 100000 | = | 2^5 | = | 32 | |
1000000 | = | 10^6 | 1000000 | = | 2^6 | = | 64 |
These are simply powers of 10 and powers of 2. The similarities between the two number systems are quite evident and most, if not all, assembly language programmers should have seen individual bits in a byte referred to as powers powers of 2. The usage of powers of two in all probability explains why the bits in a byte are numbered from 0 to 7 rather than from 1 to 8.
The relationship between logarithms and powers is extremely close as can be seen from the examples below:
log10 of | 1 | = 0 | log2 of | 1 | = 0 |
log10 of | 10 | = 1 | log2 of | 2 | = 1 |
log10 of | 100 | = 2 | log2 of | 4 | = 2 |
log10 of | 1000 | = 3 | log2 of | 8 | = 3 |
log10 of | 10000 | = 4 | log2 of | 16 | = 4 |
log10 of | 100000 | = 5 | log2 of | 32 | = 5 |
log10 of | 1000000 | = 6 | log2 of | 64 | = 6 |
Logarithms of intermediate values do not fall on a linear scale. i.e. log10 of 50 is not 1.5 but is, in fact, 1.69897 to five decimal places. That is to say that 10^1.69897 = 50. Base 2 logarithms follow exactly the same rules as for base 10 logs. Log2 of 3 is 1.58496 to five decimal places. i.e. 2^1.58496 = 3.
The integral part of a logarithm is known as the characteristic and the fractional part is known as the mantissa. For the purposes of explaining BSH, only the characteristic the base 2 logarithm is required. To simplify matters further, Digital Research have kindly done the calculations for us so if you came out of the last couple of paragraphs with a headache, don’t worry.
For completeness, I have copied the tables for the values of BLM and BSH provided by Digital Research. The values, as may be expected, are dependant upon block size (BLS).
BLS | BSH | BLM |
---|---|---|
1024 | 3 | 7 |
2048 | 4 | 15 |
4096 | 5 | 31 |
8192 | 6 | 63 |
16384 | 7 | 127 |
Having obtained values for BSH from the table (or by calculation), what are they used for? Below is a simple program in BASIC that will calculate with a remainder. This program is normally used to calculate values for a 16 bit POKE (i.e. to two consecutive memory location) where X may contain any value between 0 and 65535.
Page 17 of 55 |
---|