ID 1200IK. 1210IF T>6 THEN TB=5*(T-6)POSITION TB+1,(T>6)«2+12:PRINT B(T> j :IFB(T) tS2-S2 + SP:BOTO 1460IF P»»"C" THEN SC-B(F>iSl-Sl+SCB
INSIGHT:AtariBillWilkinsonNumber-BaseConversionsThis column was prompted by aletter in COMPUTEI's letters column, in which the author asked fora program to convert decimal numbers to binary. "Why," I asked myself, "do all these conversionprograms work with only one pairof bases (for example, base 10 tobase 2)?" Answer: because few realize that a more general program isalmost as easy these specific ones.Don't believe me? Keep reading.Number BasesYou probably learned about number bases back in third or fourthgrade, though you might not haverealized that's what you were learning. Specifically, you likely weretaught that the number 735 represented "seven hundreds, three tens,and five ones." The fact that digits ina number represent powers of ten iskind of an accident. If humans werenormally born with only three fingers and a thumb on each hand, youcan bet that 735 would have meant"seven sixty-fours, three eights, andfive ones" (that is, we would haveused base 8).Since computers are "born"with only two "fingers," their natural tendency is to use base 2, alsoknown as binary numbers or notation. (A computer's "fingers" are itsmemory cells, but each cell can remember only off or on, equivalentin function to counting on two human fingers.) Yet you seldom see acomputer memory dump printed inbinary, simply because such aprintout would be gigantic! Binarynumbers take up a lot of room compared to equivalent decimal numbers. Instead, because of the neatway that powers of two can begrouped together, we tend to seecomputer memory represented ineither octal (base 8) or hexadecimal(base 16) notation.One thing you may have noticed is that a base's number is thesame as the number of countingsymbols needed to represent it.Thus base 10 uses 0-9. Base 8 usesonly 0-7. What about bases beyond10, such as base 16, the hexadecimal base most often used in microcomputer work? Doesn't it need 16counting symbols? Yes, indeed, andthe symbols most commonly usedare 0-9, followed by A-F. (Why notuse completely new symbols for thedigits beyond 9? Simple: Early computer printers had only 64 differentsymbols available, so uppercase letters were used.)Why Hex?Sidelight: Since we are working oncomputers that tend to work withbytes, and since a byte can have avalue from 0 to 255 (decimal), base256 notation would seem to be alogical choice. But now we can seewhy it is not used—humans wouldbe forced to learn 256 unique digitsymbols! Still, there are two "nybbles"in each byte, and a nybble canhave a value from 0 to 15 (decimal),so hexadecimal (base 16) notation isa very logical alternative.Now, when you see a hexadecimal number such as A88C, whatdoes it mean? Well, you can readthat as "A four-thousand-ninetysixes,8 two-hundred-fifty-sixes, 8sixteens, and C ones." In turnthough, A and C may be read indecimal as 10 and 12, respectively.Whew! Now how about base 19?Confused? Don't worry, help isat hand. Program 1 consists of ashort main program followed bytwo special-purpose subroutines.These routines are designed tomake it easy to allow entry anddisplay of any number using anybase or pair of bases. The first one(from line 9200 to line 9330) takes anumber in variable N and convertsit to a string in variable N$ usingthe number base given by the variable BASE. The second routine(lines 9400-9560) performs thereverse operation, converting astring in N$ (which is supposed tobe a number in BASE notation) andconverting it to N for use as a number anywhere in BASIC.Try it. Type in the main codeand the subroutines and try the various options. And use some bizarrenumber bases, such as 13 or 37 or53. In keeping with the tradition ofhexadecimal numbering, the digitsymbols used are 0-9 (same as decimal for the first ten symbols), followed by A-Z, and then a-z (goodenough for anything up to base 62!).So now I have one set of routines which take care of all conversions. And it's kind of fun. Youcould even make a game of it: Tryto make two English words "equal"by changing bases! For example,RIB base 35 equals some animal(which happens to enjoy ribs) insome other base. Can you find theanimal word and its base? Maybetricks like this could make a hardto-breakencryption scheme? (Thiscan really cause you to lose sleep!)Be Just A Bit WiserI couldn't quit with simple numberconversions, of course. One of thehandy features of most higher-levellanguages is (usually) the presenceof operators which do bitwise operations. I like such operators somuch I put them into the first of theadvanced Atari-compatible BASICswe did, way back in 1981. Unfortunately, Atari BASIC does not havebitwise operators. In Atari BASIC,operators such as AND and OR always perform logical comparisonsrather than bitwise comparisons.Though, in fairness, I should pointout that there are occasions whereAtari's logical operators are worthas much as or more than bitwiseoperators. Some authors haveagreed with me to the extent thatthey have written machineFebruary 1987 COMPUTEI 73
- Page 2 and 3:
We just did something only the best
- Page 4 and 5:
icate Maker!Because accomplishments
- Page 6 and 7:
Editor'sNotesThis is the 81st issue
- Page 8 and 9:
PublisherFounder/Editor in ChlelSen
- Page 10 and 11:
Selby BatemanFeatures Editor....
- Page 12 and 13:
, ■■-■■'■ ;-.-..■■■
- Page 14 and 15:
The new Compaq Deskpro 386 is among
- Page 16 and 17:
Selby Bateman, Features Editoricrop
- Page 18 and 19:
68030 chip, which should be readyfo
- Page 20 and 21:
computer are often called proprieta
- Page 22 and 23:
Tom R. Halfhill, Staff Editorore By
- Page 24 and 25: Selby Bateman, Features Editorasers
- Page 26 and 27: MicroscopeSheldonLeemonThe new Appl
- Page 29 and 30: Fly to Florida!Scenery Disk # 7 cov
- Page 31 and 32: contains twice as many vertical pix
- Page 33 and 34: And you don't even have toleave you
- Page 35 and 36: Increase your knowledge about all a
- Page 37 and 38: BEST SERVICE IN THE USA • ONEDAY
- Page 39 and 40: BATTERIES Sg? INCLUDEDTHE FOUR LETT
- Page 41 and 42: LYCOCOMPUTERMARKETING & CONSULTANTS
- Page 43 and 44: ATARIJKLYCOCOMPUTERMARKETING & CONS
- Page 45 and 46: QuickProDOSCatalog For AppleLarrySh
- Page 47 and 48: Behaved Batch FilesCOPY CON: YESNO.
- Page 49 and 50: ASC II ExpressBalance of PowerBally
- Page 51 and 52: END**Beap:*SOUND 800,1,100,0:SOUND
- Page 53 and 54: COMMODOREAPPLEC64 COMPUTER C-128COM
- Page 55 and 56: FileCompressorChrisRogersThis Commo
- Page 57 and 58: character n. Whenever File Compress
- Page 59 and 60: \Make Your ChoiceC-64 or C-128BASIC
- Page 61 and 62: RP0A71i4C0A79:1B0A81:0A0A89:1F0A91i
- Page 63 and 64: ACCOLADEHardball 24.95Mean 18 31.95
- Page 65 and 66: Ibefore a move is made. Each compar
- Page 67 and 68: PH 1390 IF P$="C" AND T0>=7 THEN .1
- Page 69 and 70: 5D 2310 DATA 30,34,34,30,2,2,2,0FE
- Page 71 and 72: I10 630 P$="C"BC 640 REM tt PICK BE
- Page 73: ,——■———U-J>G>Player■p
- Page 77 and 78: EMPX,TEMPY,MASKBH 9140 TEMPX-X1TEMP
- Page 79 and 80: AmigaViewSheldonLeemonThe Latest Am
- Page 81 and 82: Computers and SocietyDavid D. Thorn
- Page 83 and 84: RUSH POSTAGE-PAID CARDFOR YOUR FREE
- Page 85 and 86: Train with NRI for a high payingcar
- Page 87 and 88: PersonalComputingDonald B. irivette
- Page 89 and 90: 3M DiskettesICEI has an outstanding
- Page 91 and 92: key (Atari logo key on 400/800 mode
- Page 93 and 94: MLXMachine Language Entry ProgramFo
- Page 95 and 96: THEN PRINT IN?iPRINTM{UP][5 RIGHT}"
- Page 97 and 98: When you want to talk price.AmdekMO
- Page 99 and 100: THE LOWESTTHE BESTPRICESSERVICEELEC
- Page 101 and 102: fNOWAVAILABLE AT24$O>!00The Mew Car
- Page 103 and 104: COMPUTERSFREE Reader Information Se
- Page 105 and 106: STARGLIDERJJtarglider — is an all