Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,47 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "bigint.s7i";
|
||||
|
||||
const func string: toSequence (in var bigInteger: number) is func
|
||||
result
|
||||
var string: sequence is "";
|
||||
begin
|
||||
sequence := str(chr(ord(number mod 128_)));
|
||||
number >>:= 7;
|
||||
while number <> 0_ do
|
||||
sequence := str(chr(ord(number mod 128_) + 128)) & sequence;
|
||||
number >>:= 7;
|
||||
end while;
|
||||
end func;
|
||||
|
||||
const func bigInteger: fromSequence (in string: sequence) is func
|
||||
result
|
||||
var bigInteger: number is 0_;
|
||||
local
|
||||
var integer: index is 1;
|
||||
begin
|
||||
while ord(sequence[index]) >= 128 do
|
||||
number <<:= 7;
|
||||
number +:= bigInteger conv (ord(sequence[index]) - 128);
|
||||
incr(index);
|
||||
end while;
|
||||
number <<:= 7;
|
||||
number +:= bigInteger conv ord(sequence[index]);
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
const array bigInteger: testValues is [] (
|
||||
0_, 10_, 123_, 254_, 255_, 256_, 257_, 65534_, 65535_, 65536_, 65537_, 2097151_, 2097152_);
|
||||
var string: sequence is "";
|
||||
var bigInteger: testValue is 0_;
|
||||
var char: element is ' ';
|
||||
begin
|
||||
for testValue range testValues do
|
||||
sequence := toSequence(testValue);
|
||||
write("sequence from " <& testValue <& ": [ ");
|
||||
for element range sequence do
|
||||
write(ord(element) radix 16 lpad0 2 <& " ");
|
||||
end for;
|
||||
writeln("] back: " <& fromSequence(sequence));
|
||||
end for;
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue