Commodore 64 User Manual page 88

Hide thumbs Also See for 64:
Table of Contents

Advertisement

Using combinations of all eight bits, you can obtain any decimal value
from 0 to 255. Do you start to see why when we POKEd character or
color values into memory locations the values had to be in the 0-255
range? Each memory location can hold a byte of information.
Any possible combination of eight 0's and l's will convert to a
unique decimal value between 0-255. If all places contain a 1 then the
value of the byte equals 255. All zeros equal a byte value of zero;
"00000011" equals 3, and so on. This will be the basis for creating data
that represents sprites and manipulating them. As just one example, if
this byte grouping represented part of a sprite (0 is a space, 1 is a
colored area):
2t 2s
25
24
23
22
21
20
128+ 64 +
32+ 16+ 8 + 4+ 2+ 1 + = 255
Then we would POKE 255 into the appropriate memory location to
represent that part of the object.
T1PF
To save you the trouble of converting binary numbers into decimal values-we'll
need to do that a lot-the following program will do the work for you. It's a good
idea to enter and save the program for future use.
5 REM BINARY TO DECIMAL CONVERTER
10 INPUT "ENTER 8-BIT BINARY NUMBER :":A$
12 IF LEN (A$) :: 8 THEN PRINT "8 BITS PLEASE...":
GOTO 10
15 TL = 0 : C = 0
20 FOR X = 8 to 1 STEP -1 : C = C_. + 1
30 TL = TL + VAL(MID$(A$,C,1))*2f(X-1)
40 NEXT X
50 PRINT A$;" BINARY = ";TL;" DECIMAL"
60 GOTO 10
This program takes your binary number, which was entered as a string , and looks
at each character of the string, from left to right (the MID$ function). The variable C
indicates what character to work on as the program goes through the loop.
The SAL function, in line 30, returns the actual value of the character. Since we
are dealing with numeric characters, the value is the same as the character. For
example , if the first character of AS is 1 then the value would also be 1.
The final part of line 30 multiplies the value of the current character by the proper
power of 2. Since the first value is in the 2T7 place, in the example, TL would first
equal 1 times 128 or 128. If the bit is 0 then the value for that place would also be
zero.
This process is repeated for all eight characters as TL keeps track of the running
total decimal value of the binary number.
S
0
S
0
s
s
78
0
S

Hide quick links:

Advertisement

Table of Contents
loading

Related Products for Commodore 64

Table of Contents