Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- report zz_test_binary.
- parameters: x type x length 20 default '8060403A' visible length 40.
- * Binary Digit Sums
- * The following is an optimized algorithm to compute the binary digit sum
- * of an hex string (should work for arbitrary length)
- * If a bit sequence is used to model a set, the binary digit sum can be
- * interpreted as the cardinality of the set.
- * DSUM256 should be a CONSTANT, but a literal can only have 255 characters...
- data gc_dsum256(256) type x.
- perform build_dsum256 changing gc_dsum256.
- data: sum type i value 0,
- count type i,
- byte type x.
- write: / x.
- count = xstrlen( x ).
- while count > 0.
- subtract 1 from count.
- byte = x+count(1).
- sum = sum + gc_dsum256+byte(1).
- endwhile.
- write: / '... has binary digit sum', sum.
- form build_dsum256 changing cv_dsum256 type raw256.
- data: part(32) type x,
- partoff type i value 0.
- define _build_dsum256.
- part = &1.
- cv_dsum256+partoff(32) = part.
- add 32 to partoff.
- end-of-definition.
- _build_dsum256 :
- '0001010201020203010202030203030401020203020303040203030403040405',
- '0102020302030304020303040304040502030304030404050304040504050506',
- '0102020302030304020303040304040502030304030404050304040504050506',
- '0203030403040405030404050405050603040405040505060405050605060607',
- '0102020302030304020303040304040502030304030404050304040504050506',
- '0203030403040405030404050405050603040405040505060405050605060607',
- '0203030403040405030404050405050603040405040505060405050605060607',
- '0304040504050506040505060506060704050506050606070506060706070708'.
- * Digit sums of the first 256 numbers,
- * computed in a JS console with the following code block:
- *
- * t=[];s="'";for (var i=0;i<256;i++) { s+= "0"+(function(i){
- * s = 0; while (i > 0) { s += (i%2); i = i>>1; } return s;
- * })(i); if ((i+1)%32==0){t.push(s+"'");s="'"}};t.join(",\n")+"."
- *
- endform.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement