Ad: Click Here

Mapping the Atari cover

APPENDIX NINE

Numerical Conversions

If you use this map a lot, or use the Atari a lot for machine language routines, interrupts, graphics and the like, you know the need to translate between decimal and hexadecimal, even back and forth with binary, frequently. It is possible, although tedious, to do your translations by hand, using pencil and paper. The tables for doing so are below. It's not the best nor the fastest method available. I recommend you get the Texas Instruments TI Programmer calculator. It does most of this work for you, plus bit manipulation (unfortunately it does not offer binary translation). It's an indispensable tool for programmers. There are other ways around buying the calculator: you can buy Monkey Wrench from Eastern House Software, which will do the hex - decimal translations for you quite nicely. Or you can buy any of the numerous disk or programming utilities which include such translation routines, such as Disk Scan from Micro Media. However, those who wish to do the work themselves can use a simple translator program. One such example, modified from routines that appeared separately in COMPUTE!, November 1981 and March 1982, is: 10 DIM HEX$(16),DEC$(23),NUM$(10),W$( 4),BIN$(8),BNY$(8),TRANS(8) 15 DATA 128,64,32,16,8,4,2,1 20 FOR N=1 TO 8:READ B:TRANS(N)=B:NEX T N:POKE 201,14 25 PRINT CHR$(125) 30 HEX$="0123456789ABCDEF":DEC$"=@ABC DEFGHI!!!!!!!JKLMNO" 40 ?:?"PRESS [OPTION] FOR HEXADECIMAL": ?"{6 SPACES}[SELECT] FOR DECIMAL":?" {6 SPACES}[START] FOR BINARY" 42 ?"{6 SPACES}TRANSLATIONS":A=1:MAX= 4096 50 IF PEEK(53279)=3 THEN GOTO 100 60 IF PEEK(53279)=5 THEN GOTO 200 70 IF PEEK(53279)=6 THEN GOTO 300 80 GOTO 50 100 ? : ?"ENTER HEXADECIMAL NUMBER":"? "$0000 TO $FFFF": INPUT NUM$:ACC= 0:A=1:TRAP 100 120 FOR NUM=1 TO LEN(NUM$):ACC=ACC*16 +ASC(DEC$(ASC(NUM$(NUM))-47))-64: NEXT NUM:T=ACC 125 IF ACC>255 THEN BNY$="........":G OTO 170 130 FOR N=7 TO 0 STEP-1:BIN=2^N 135 IF INT(ACC/BIN)=l THEN BNY$(A,A)= "1":ACC=ACC-BIN:GOTO 150 140 BNY$(A,A)="0" 150 A=A+1:NEXT N 170 ?:?"HEXADECIMAL","DECIMAL","BINA RY" 180 ? " ";NUM$,T,BNY$ 190 ? :? : GOTO 40 200 ? :? "ENTER DECIMAL NUMBER": ?"0 TO 65535": INPUT NUM:T=NUM:Z=T:MA X=4096:TRAP 200 205 IF NUM>65535 THEN GOTO 200 208 IF NUM<1 THEN GOTO 200 210 FOR N=1 TO 4:BYTE=INT(NUM/MAX):W$ (N,N)=HEX$(BYTE+1,BYTE+1):NUM=NUM -MAX*BYTE:MAX=MAX/16:NEXT N 220 IF T>255 THEN BNY$="........": GOT O 270 230 FOR N=7 TO 0 STEP -1:BIN=2^N 235 IF INT(Z/BIN)=1 THEN BNY$(A,A)="1 ":Z=Z-BIN:GOTO 250 240 BNY$(A,A)="0" 250 A=A+1:NEXT N 270 ?:?"DECIMAL","HEXADECIMAL","BINAR Y" 280 ? " ";T,W$,BNY$ 290 GOTO 40 300 ? :? "INPUT BINARY NUMBER":?"0000 0000 TO 11111111":? :?"76543210 B ITS":INPUT BIN$:TRAP 300 305 IF LEN(BIN$)<>8 THEN GOTO 300 308 FOR B=1 TO 8:IF VAL(BIN$(B,B))>1 THEN POP:GOTO 300 310 NEXT B 320 FOR B=1 TO 8:IF BIN$(B,B)="1" THE N TOT=TOT+TRANS(B) 325 NEXT B: Q=TOT 330 FOR L=1 TO 4:BYTE=INT(TOT/MAX):W$ (L,L)=HEX$(BYTE+1,BYTE+1):TOT=TOT -MAX*BYTE:MAX=MAX/16:NEXT L 340 ?:?"BINARY","HEXADECIMAL","DECIMA L" 350 ? " ";BIN$,W$,Q 390 GOTO 40 DOWNLOAD CONVERT.BAS This program will translate any hexadecimal, decimal, and binary number to and from the others. There are some constraints in its use: it will not translate a binary number for any hex number larger than $FF or decimal number larger than 255. It will not translate any hex number larger than $FFFF or any decimal number larger than 65535. Since about 99% of your numeric manipulations will be within these ranges, you should have no problems. You can easily remove the translation routines from the program for use in your own utility. For a quick way to translate any number in the range of zero to 65535 ($FFFF), use the table below. It's quite simple to use: to translate hex to decimal you take the number that appears in the column that corresponds to the value in the proper row and add the values together. The total is your decimal number. For example: $7AC1 = 28672 fourth column, 7 2560 third column, A 192 second column, C 1 first column, 1 ----- 31425 decimal value To translate decimal into hex, you find the largest number less than the number you wish to translate and subtract it from your original number. The value in the row is the first hexadecimal value. You then do the same with the remainder until your result is zero. The values in the row are then concatenated together for a hexadecimal number. For example: 31425 = 31425 - 28672 largest number, column four. first hex number = 7 ----- 2753 remainder, minus third column 2560 second hex number = A ----- 193 remainder, minus second column 192 third hex number = C ----- 1 remainder and fourth hex number Hexadecimal value = $7AC1 Hex Column Hex number fourth third second first number 1 4096 256 16 1 1 2 8192 512 32 2 2 3 12288 768 48 3 3 4 16384 1024 64 4 4 5 20480 1280 80 5 5 6 24576 1536 96 6 6 7 28672 1792 112 7 7 8 32768 2048 128 8 8 9 36864 2304 144 9 9 A 40960 2560 160 10 A B 45056 2816 176 11 B C 49152 3072 192 12 C D 53248 3328 208 13 D E 57344 3584 224 14 E F 61440 3840 240 15 F The next few pages are simply a listing of the decimal, hex,and binary values for the range of numbers between zero and 255. I have found this listing to be extremely useful when I couldn't enter a translator program or lay my hands on a calculator. Read the note in the introduction regarding the translation techniques for binary and hexadecimal. Decimal Hex Binary Decimal Hex Binary Decimal Hex Binary 0 0 00000000 34 22 00100010 68 44 01000100 1 1 00000001 35 23 00100011 69 45 01000101 2 2 00000010 36 24 00100100 70 46 01000110 3 3 00000011 37 25 00100101 71 47 01000111 4 4 00000100 38 26 00100110 72 48 01001000 5 5 00000101 39 27 00100111 73 49 01001001 6 6 00000110 40 28 00101000 74 4A 01001010 7 7 00000111 41 29 00101001 75 4B 01001011 8 8 00001000 42 2A 00101010 76 4C 01001100 9 9 00001001 43 2B 00101011 77 4D 01001101 10 A 00001010 44 2C 00101100 78 4E 01001110 11 B 00001011 45 2D 00101101 79 4F 01001111 12 C 00001100 46 2E 00101110 80 50 01010000 13 D 00001101 47 2F 00101111 81 51 01010001 14 E 00001110 48 30 00110000 82 52 01010010 15 F 00001111 49 31 00110001 83 53 01010011 16 10 00010000 50 32 00110010 84 54 01010100 17 11 00010001 51 33 00110011 85 55 01010101 18 12 00010010 52 34 00110100 86 56 01010110 19 13 00010011 53 35 00110101 87 57 01010111 20 14 00010100 54 36 00110110 88 58 01011000 21 15 00010101 55 37 00110111 89 59 01011001 22 16 00010110 56 38 00111000 90 5A 01011010 23 17 00010111 57 39 00111001 91 5B 01011011 24 18 00011000 58 3A 00111010 92 5C 01011100 25 19 00011001 59 3B 00111011 93 5D 01011101 26 1A 00011010 60 3C 00111100 94 5E 01011110 27 1B 00011011 61 3D 00111101 95 5F 01011111 28 1C 00011100 62 3E 00111110 96 60 01100000 29 1D 00011101 63 3F 00111111 97 61 01100001 30 1E 00011110 64 40 01000000 98 62 01100010 31 1F 00011111 65 41 01000001 99 63 01100011 32 20 00100000 66 42 01000010 100 64 01100100 33 21 00100001 67 43 01000011 101 65 01100101 Decimal Hex Binary Decimal Hex Binary Decimal Hex Binary 102 66 01100110 163 A3 10100011 224 E0 11100000 103 67 01100111 164 A4 10100100 225 E1 11100001 104 68 01101000 165 A5 10100101 226 E2 11100010 105 69 01101001 166 A6 10100110 227 E3 11100011 106 6A 01101010 167 A7 10100111 228 E4 11100100 107 6B 01101011 168 A8 10101000 229 E5 11100101 108 6C 01101100 169 A9 10101001 230 E6 11100110 109 6D 01101101 170 AA 10101010 231 E7 11100111 110 6E 01101110 171 AB 10101011 232 E8 11101000 111 6F 01101111 172 AC 10101100 233 E9 11101001 112 70 01110000 173 AD 10101101 234 EA 11101010 113 71 01110001 174 AE 10101110 235 EB 11101011 114 72 01110010 175 AF 10101111 236 EC 11101100 115 73 01110011 176 B0 10110000 237 ED 11101101 116 74 01110100 177 B1 10110001 238 EE 11101110 117 75 01110101 178 B2 10110010 239 EF 11101111 118 76 01110110 179 B3 10110011 240 F0 11110000 119 77 01110111 180 B4 10110100 241 F1 11110001 120 78 01111000 181 B5 10110101 242 F2 11110010 121 79 01111001 182 B6 10110110 243 F3 11110011 122 7A 01111010 183 B7 10110111 244 F4 11110100 123 7B 01111011 184 B8 10111000 245 F5 11110101 124 7C 01111100 185 B9 10111001 246 F6 11110110 125 7D 01111101 186 BA 10111010 247 F7 11110111 126 7E 01111110 187 BB 10111011 248 F8 11111000 127 7F 01111111 188 BC 10111100 249 F9 11111001 128 80 10000000 189 BD 10111101 250 FA 11111010 129 81 10000001 190 BE 10111110 251 FB 11111011 130 82 10000010 191 BF 10111111 252 FC 11111100 131 83 10000011 192 C0 11000000 253 FD 11111101 132 84 10000100 193 C1 11000001 254 FE 11111110 133 85 10000101 194 C2 11000010 255 FF 11111111 134 86 10000110 195 C3 11000011 135 87 10000111 196 C4 11000100 136 88 10001000 197 C5 11000101 137 89 10001001 198 C6 11000110 138 8A 10001010 199 C7 11000111 139 8B 10001011 200 C8 11001000 140 8C 10001100 201 C9 11001001 141 8D 10001101 202 CA 11001010 142 8E 10001110 203 CB 11001011 143 8F 10001111 204 CC 11001100 144 90 10010000 205 CD 11001101 145 91 10010001 206 CE 11001110 146 92 10010010 207 CF 11001111 147 93 10010011 208 D0 11010000 148 94 10010100 209 D1 11010001 149 95 10010101 210 D2 11010010 150 96 10010110 211 D3 11010011 151 97 10010111 212 D4 11010100 152 98 10011000 213 D5 11010101 153 99 10011001 214 D6 11010110 154 9A 10011010 215 D7 11010111 155 9B 10011011 216 D8 11011000 156 9C 10011100 217 D9 11011001 157 9D 10011101 218 DA 11011010 158 9E 10011110 219 DB 11011011 159 9F 10011111 220 DC 11011100 160 A0 10100000 221 DD 11011101 161 A1 10100001 222 DE 11011110 162 A2 10100010 223 DF 11011111

Return to Table of Contents | Previous Chapter | Next Chapter