When using the IN function to read the Spectrum keyboard (as described on page 160 of the Spectrum manual), it is useful to know the state of individual bits of the number read, i.e. it's desirable to have the number returned in binary.
However, there is no command in Spectrum Basic to convert decimal numbers to binart. This short machine code routine will do just that, providing the first program line is:
1 DIM a$(8)
The string dimensioned in the first line will contain the pattern of the result of the equivalent IN function.
Type in the program as shown. The routine may be placed anywhere in memory (the disassembly shows it in user graphic area of a 48K machine but it can be placed anywhere, just replace start with the start address chosen).
When the routine is in memory it is used as follows: before calling the line, RANDOMISE n must be present (where n is the number from the Spectrum manual of the half row to be read). This should be used just before the routine is called with:
LET XX = USR start (where start is the start address of the routine)
Thee string dimensioned in line 1 will now contain the binary equivalent of the result of an equivalent IN function.
10 RESTORE : FOR n=START TO START+28
20 READ a: POKE n,a: NEXT n
30 DATA 237,75,118,92,42,75,92,17,6,0,25,137,120,6,8,54,48,203,127,40,2,54,49,203,23,
35,16,243,201