Beginning Programming: ZX81 Math

Author(s): William Wentz
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n9 (Volume 3, Issue 9)
Date: September 1982
Pages: 8

Computing newcomers often face new terminology. This article expands on bits, bytes and binary numbers over the ZX81 and TS1000 manual.


An elementary understanding of the mathematics involved with your computer will help you get the most enjoyment and use out of it. Your computer is a digital machine, or “number cruncher.” When you press a key, whether it is an alpha character (letter), graphic symbol or numeral, it is immediately converted to a numerical value. If you hate math, don’t quit yet–we’ll start at the beginning.

When we count up from 1, we run out of single digits after 9. So we go to double digits. The number 10 means one ten and no ones; 11 means one ten and one one, and so on. You understand the meaning of each digit by its position in the numeral.

Let’s look at the numeral 6382, read six thousand three hundred and eighty-two. We can break it down like this:

6382=(6*1000)+(3*100)+(8*10)+(2*1)

The number 1000 is the same as 10x10x10, or 10 cubed. It can be written symbolically as 10³ (10 raised to the third power). The 3 in 10³ is called the exponent and is written to the right and above the number being raised. Since we cannot enter an exponent this way on the ZX81, the symbol ** (shifted H) is used, eg., 10**3. We can now write the equation for our number using exponents:

6382=6*10³+3*10²+8*10¹+2*10¹

As you see, 10 raised to the zero power equals 1. Try it on your computer (PRINT 10**0). So our usual number system consists of 10 digits and is based on 10 raised to a power, said to be base 10. We call this system DECIMAL, or more correctly, DECIMAL NOTATION.

Your computer consists of thousands of transistors used as electronic switches. A switch has only two positions, on and off. So the number system used to express what’s happening within the computer is quite different from the decimal notation we are used to. Because a switch has only two states, we need only two digits, 0 and 1, and our number system will be base 2. This system is called BINARY. A BInary digiT is called a bit. Let’s take the 4-bit binary number 1101 and express it in exponential form as we did to the decimal number. Remember that a binary number is in base 2.

1101=(1*2³)+(1*2²)+(0*2¹)+(1*2⁰)
    = 1*8 + 1*4 + 0*2 + 1*1
    =   8 +   4 +   0 +   1
    = 13 in decimal

By putting a binary number in exponential form we can convert it to its decimal equivalent. But how do you go from decimal to binary? If you don’t have a computer program to do it for you, you can use the method of succesive subtraction of powers of two. The name is the worst part. Let’s take the decimal number 13. Start by finding the largest power of 2 that will divide into 13. Then divide the remainder by the next lower power of 2:

2⁴=16 13/16  Too Big
                          2³ 2² 2¹ 2⁰
2³=8  13/8=1 remainder 5  1
2²=4   5/4=1 remainder 1     1
2¹=2   1/2=0 remainder 1        0
2⁰=1   1/1=1                       1

So decimal 13= binary 1101.

The Z80 microprocessor chip used in the ZX81 and TS1000 is an 8-bit device, meaninvg that it can handle 8 binary digits of data at one time. This grouping of 8 bits is called a byte. So we can say that each memory location in our computer is a byte wide. When we express a byte in binary notation, it is customary to write all 8 bits, even though there are leading zeros. For example, binary 1 is written as 00000001.