CompuServe Messages

Your LCDIO.TXT

    13-Nov-85 01:50:45
Sb: Your LCDIO.TXT
Fm: Tim Peters 72227,2416
To: Mike Safonov 70506,1473
Mike, I really enjoyed your LCDIO writeup – excellent coverage & solid info. Thank you much for sharing it with us! A family of bitstring-reversal tricks I hope YOU enjoy: there's a faster way to reverse a byte than calling an ML subroutine: since there are only 256 values, the reversals can be PREcomputed and saved in a DATA stmnt to be read into a 256-element array (say, R%) at the program's start. Then, eg, replacing A% by its reversal is simply A%=R%(A%). If BLINDING speed is important, it's worth the space. I've used a variation of that trick in assembler on a mainframe to reverse 64bit words quickly: if a sequence S is a concatenation of sequence S1 and sequence S2, then the reverse of S is the reverse of S2 concatenated with the reverse of S1 (of course, the same idea can be applied recursively to S1 & S2, too; & so on). E.g., on the M100, a byte can be reversed by reversing its constituent nibbles individually & swapping them: 1 DIM R%(15) 2 DATA 0,8,4,12,2,'etc.: reversed nibbles 3 FOR I=0 TO 15:READ R%(I):NEXT Then byte A% can be reversed by: A%=R%(A%AND15)*16+R%(A%\16) More computation traded for less space, right? Fun stuff… obscurely y'rs – tim