Scor­pio News

  

October–December 1987 – Volume 1. Issue 4.

Page 17 of 55

A beginners guide to base 2 logarithms

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:

DecimalBinaryEquivalent
1=10^01=2^0=1
10=10^110=2^1=2
100=10^2100=2^2=4
1000=10^31000=2^3=8
10000=10^410000=2^4=16
100000=10^5100000=2^5=32
1000000=10^61000000=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 of1= 0log2 of1= 0
log10 of10= 1log2 of2= 1
log10 of100= 2log2 of4= 2
log10 of1000= 3log2 of8= 3
log10 of10000= 4log2 of16= 4
log10 of100000= 5log2 of32= 5
log10 of1000000= 6log2 of64= 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.

How BSH, BLM and EXM are used

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).

BLSBSHBLM
102437
2048415
4096531
8192663
163847127

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