home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.misc      General topics about computers not cover      21,759 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 20,982 of 21,759   
   Ben Collver to All   
   On Binary Digits (5/5)   
   01 Apr 25 15:58:47   
   
   [continued from previous message]   
      
           retval = f2p[triplet1] "-" s2p[triplet2]   
       }   
       return retval   
   }   
      
   # zero pad number until length is a multiple of 4 digits   
      
   function zpad4(str,    pad, rem) {   
       rem = length(str) % 4   
       if (rem > 0) {   
           pad = substr("0000", 1, 4 - rem)   
           str = pad str   
       }   
       return str   
   }   
      
   # zero pad number until length is a multiple of 6 digits   
      
   function zpad6(str,    pad, rem) {   
       rem = length(str) % 6   
       if (rem > 0) {   
           pad = substr("000000", 1, 6 - rem)   
           str = pad str   
       }   
       return str   
   }   
      
   function main(    i, result, val) {   
       for (i = 1; i < ARGC; i++) {   
           if (length(val) == 0) {   
               val = ARGV[i]   
           } else {   
               val = val " " ARGV[i]   
           }   
       }   
       if (length(val) == 0) {   
           print "Usage: pohlcode.awk [code|number|test]"   
           print ""   
           print "[code]:   Converts Pohl code to decimal."   
           print "[number]: Converts decimal to Pohl code."   
           print "test:     Print test output."   
           exit 1   
       }   
       sub(/\n$/, "", val)   
       init()   
       if (val == "test") {   
           test()   
       } else if (val ~ /^[0-9][0-9]*$/) {   
           result = bin2pohl(dec2bin(val))   
       } else {   
           result = bin2dec(pohl2bin(val))   
       }   
       print result   
       return   
   }   
      
   function test(    code, i, j) {   
       for (i = 0; i < 1024; i++) {   
           code = bin2pohl(dec2bin(i))   
           j = bin2dec(pohl2bin(code))   
           printf "%d\t%s\t%d\n", i, code, j   
       }   
       return   
   }   
      
   BEGIN {   
       main()   
       exit 0   
   }   
   __EOF__   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca