Recent

Author Topic: Please help  (Read 10496 times)

q250

  • New Member
  • *
  • Posts: 20
Re: Please help
« Reply #15 on: November 14, 2023, 01:23:08 am »
I dont think so.
no, he right, exactly this. also death of Jan Sloot is not becouse of his poor health, its murder. i even got first suspect.
he want to compute exact 1kb (1024 byte/8192 bit).
no, number 8192 is arbitray, you can replace it with any another.
take a look on Pascals Integer types and its sizes, since what you write is currently with normal data types impossible to do in one step.
also still computing example. also check naming rule in windows, turn out we dont need exemption in our naming rule, just add .cmprs (short from compression) in end in subroutines 1 and remove in subroutines 2.

q250

  • New Member
  • *
  • Posts: 20
Re: Please help
« Reply #16 on: November 14, 2023, 02:24:58 am »
ok, file "test.cmprs" and it content is
Code: Pascal  [Select][+][-]
  1. 00000000000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001111
N - number of bits, bits, not bytes, of that string = 128
D10 - string value in base10, ignoring all zeroes from left = 5233100606242806050955395731361295
A - that string value in table M, see above = D10 + 2^N <- this where i made mistake = 340287600021544706269425562827499572751
now subtract 1 from A, ie A: = A - 1 = 340287600021544706269425562827499572750
now find binary string in M for this  to do that
find B = Floor(log from (A) base 2) = 128
find R = A – 2^B = 5233100606242806050955395731361294
now construct binary text string that equal to R in binary and add as much 0 from left as much it needed to make it overall size equal B
string that equal to R in binary =
Code: Pascal  [Select][+][-]
  1. 10000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001110
size of this string = 113
how many zeroes from left that needed to be add = B - size of that string = 15
add that zeroes to string =
Code: Pascal  [Select][+][-]
  1. 00000000000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001110
now add to that string one one from left =
Code: Pascal  [Select][+][-]
  1. 100000000000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001110
and now add even further to left as much zeroes it needed to make overall string size equal to 8192
size of this string = 129
how many zeroes needed = 8192 - size of this string = 8063
overall file would look like this:
Code: Pascal  [Select][+][-]
  1. 8063 zeroes + 100000000000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001110
now save this string under oridginal name without .cmprs, ie as "test"
end

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Please help
« Reply #17 on: November 14, 2023, 02:30:50 am »
I am still confused, is what you show there the data displayed as a string?

Heres a startup that show how to do it in a binary way. Just written in a hurry and not tested.
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   Classes, SysUtils;
  7.  
  8. function BitToByte(const AValue: UInt64): UInt64;
  9. begin
  10.   Result := AValue div 8;
  11. end;
  12.  
  13. function ByteToBit(const AValue: UInt64): UInt64;
  14. begin
  15.   Result := AValue * 8;
  16. end;
  17.  
  18. var
  19.   Filename: string;
  20.   i, Zeros, Ones: Integer;
  21.   GotExt,
  22.   GotSize,
  23.   IsZeros, IsOnes: Boolean;
  24.   ms: TMemoryStream;
  25.   b, Mask0, Mask1: Byte;
  26. begin
  27.   // no argument, exit
  28.   if ParamCount = 0 then
  29.     Exit;
  30.   // initialize all basics
  31.   Filename := '';
  32.   Zeros := 0;
  33.   Ones := 0;
  34.   GotExt := False;
  35.   GotSize := False;
  36.   IsZeros := False;
  37.   IsOnes := False;
  38.   // get filename from argument(s)
  39.   for i := 1 to ParamCount do
  40.     Filename := Filename + ParamStr(i);
  41.   // check extension
  42.   GotExt := LowerCase(ExtractFileExt(Filename)) = '.cmprs';
  43.   // check if file exists
  44.   if (not FileExists(Filename)) then
  45.     Exit;
  46.   // continue check if its not ".cmprs"
  47.   if (not GotExt) then
  48.     begin
  49.       ms := TMemoryStream.Create;
  50.       try
  51.         ms.LoadFromFile(Filename);
  52.         Mask0 := $00;
  53.         Mask1 := $FF;
  54.         // check size as bits
  55.         GotSize := ByteToBit(ms.Size) = 8192;
  56.         if GotSize then
  57.           begin
  58.             ms.Position := 0;
  59.             // iterate thru file
  60.             for i := 0 to Pred(ms.Size) do
  61.               begin
  62.                 // get a byte
  63.                 ms.ReadBuffer(b, SizeOf(Byte));
  64.                 // check if its a binary zero (00000000)
  65.                 if (b = Mask0) then
  66.                   Inc(Zeros);
  67.                 // check if its a binary one (11111111)
  68.                 if (b = Mask1) then
  69.                   Inc(Ones);
  70.                 // break loop if value neither binary zeros nor binary ones
  71.                 if ((b <> Mask0) and (b <> Mask1)) then
  72.                   Break;
  73.               end;
  74.             IsZeros := (Zeros = 8192);
  75.             IsOnes := (Ones = 8192);
  76.           end;
  77.       finally
  78.         ms.Free;
  79.       end;
  80.     end;
  81.   // from here you can continue with your subst methods depending on above computings
  82.   // GotExt = there is cmprs extension
  83.   // GotSize = file is exact 1024 byte
  84.   // IsZeros = file contain just binary zeros
  85.   // IsOnes = file contain just binary ones
  86. end.
« Last Edit: November 14, 2023, 02:44:28 am by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Fibonacci

  • Hero Member
  • *****
  • Posts: 901
  • Behold, I bring salvation - FPC Unleashed
Re: Please help
« Reply #18 on: November 14, 2023, 02:39:47 am »
8063 zeroes + 1000 (...)

What kind of data have 8k of 0's and then some meaningful bits?



Lets forget about files. Focus on algorithm. Start with something smaller.

Assume we have one 32 bit number with value 1633837924, ASCII "abcd"; 4 bytes with values 97, 98, 99, 100

Code: Pascal  [Select][+][-]
  1. 01100001 01100010 01100011 01100100

How to compress it? Step by step please, one step in one line
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

q250

  • New Member
  • *
  • Posts: 20
Re: Please help
« Reply #19 on: November 14, 2023, 03:27:04 am »
I am still confused, is what you show there the data displayed as a string?
???
what step is confused you?


What kind of data have 8k of 0's and then some meaningful bits?
dont know, dont care. only care that its works.

What kind of data have 8k of 0's and then some meaningful bits?
Lets forget about files. Focus on algorithm. Start with something smaller.
Assume we have one 32 bit number with value 1633837924, ASCII "abcd"; 4 bytes with values 97, 98, 99, 100
Code: Pascal  [Select][+][-]
  1. 01100001011000100110001101100100
How to compress it? Step by step please, one step in one line
first of all, we need to somehow save number 32. so lets assume that everywhere in our program we use 32 instead of of 8192. then
delete from that string from left all zeroes and one one, that one included = 100001011000100110001101100100
N that equal to number of bits of that string = 30
D10 that equal to that string value in base10, ignoring all zeroes from left = 560096100
A = D10 + 2^N = 1633837924
now add 1 to A, ie A: = A + 1 = 1633837925
now find binary string in M table, see above,  for this base10 number. to do that
find B = Floor(log from (A) base 2) = 30
find R = A – 2^B = 560096101
now construct binary text string that equal to R in binary and add as much 0 from left as much it needed to make it overall size equal B
string that equal to R in binary =  100001011000100110001101100101
size of this string = 30
how many zeroes from left that needed to be add = B - size of that string = 0, ie we dont add anything
Now save that string with name of original file and add .cmprs
end.

overall string
Code: Pascal  [Select][+][-]
  1. 01100001011000100110001101100100
become string
Code: Pascal  [Select][+][-]
  1. 100001011000100110001101100101

Fibonacci

  • Hero Member
  • *****
  • Posts: 901
  • Behold, I bring salvation - FPC Unleashed
Re: Please help
« Reply #20 on: November 14, 2023, 03:35:29 am »
Ok, now reverse, decompress 100001011000100110001101100101

Again step by step, one in line
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

q250

  • New Member
  • *
  • Posts: 20
Re: Please help
« Reply #21 on: November 14, 2023, 04:00:01 am »
Ok, decompress 100001011000100110001101100101
N - number of bits of that string = 30
D10 - string value in base10, ignoring all zeroes from left =  560096101
A - that string value in table M,  = D10 + 2^N = 1633837925
now subtract 1 from A, ie A: = A - 1 = 1633837924
now find binary string in M table for this. to do that
find B = Floor(log from (A) base 2) = 30
find R = A – 2^B = 560096100
now construct binary text string that equal to R in binary and add as much 0 from left as much it needed to make it overall size equal B
string that equal to R in binary = 100001011000100110001101100100
size of this string = 30
how many zeroes from left that needed to be add = B - size of that string = 0
add that amount of zeroes to string from left = 100001011000100110001101100100
now add to that string one one from left = 1100001011000100110001101100100
and now add even further to left as much zeroes it needed to make overall string size equal to 32, we save that number in body of programm
size of this string = 31
how many zeroes needed = 32 - size of this string = 1
add them. overall file would look like this: 01100001011000100110001101100100
now save this string under oridginal name without .cmprs
end

Fibonacci

  • Hero Member
  • *****
  • Posts: 901
  • Behold, I bring salvation - FPC Unleashed
Re: Please help
« Reply #22 on: November 14, 2023, 04:09:01 am »
1633837924 was poorly chosen number for this, it gets "decompressed" at too early stage

Can you do the same for other number? 4091700071 = 11110011111000100110001101100111

Compress & decompress
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

q250

  • New Member
  • *
  • Posts: 20
Re: Please help
« Reply #23 on: November 14, 2023, 04:24:05 am »
of course i can, but its computer work to do monotonous calculation. i would belive that somebody still dont get how this works.

Fibonacci

  • Hero Member
  • *****
  • Posts: 901
  • Behold, I bring salvation - FPC Unleashed
Re: Please help
« Reply #24 on: November 14, 2023, 04:36:25 am »
Please do, last time. I know it's monotonous, but we need to have something to validate if program calculates it right. This number has 1's on the left and right, looks appropriate to verify the theory.
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

q250

  • New Member
  • *
  • Posts: 20
Re: Please help
« Reply #25 on: November 14, 2023, 05:16:26 am »
Please do, last time.
no. it computer work.
we need to have something to validate if program calculates it right.
what program? i dont see any programm. only i see is simple idea. size of set of all binary string with N bits(1) is 2^N. size of set of all binary string with N-1 and less bits, up to 1 bit (2), is 2^(N-1) + 2^(N-2)... +2^(1) = 2^N - 2. it means that if you remove from set (1) two elements you can do bijection of one set onto another.
and its not even hardest concept, now we need do really hard stuff. so hard, that even heavenly powers would shake and Betelgeuse blow up: column reshuffling.

Fibonacci

  • Hero Member
  • *****
  • Posts: 901
  • Behold, I bring salvation - FPC Unleashed
Re: Please help
« Reply #26 on: November 14, 2023, 05:43:01 am »
Please do, last time.
no. it computer work.

For 1633837925 it works, but not for 4091700071. Doesnt work for any number with 1's on the left. Either failure in my implementation or in your math. If you show how to calculate it for 4091700071, I will share the code.

Code: Pascal  [Select][+][-]
  1. 11110011111000100110001101100111 <- original
  2.   110011111000100110001101101000 <- compressed
  3. 01110011111000100110001101100111 <- decompressed
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

q250

  • New Member
  • *
  • Posts: 20
Re: Please help
« Reply #27 on: November 14, 2023, 06:09:24 am »
what if 10101001 and not 32 but 8 is that ok?

Fibonacci

  • Hero Member
  • *****
  • Posts: 901
  • Behold, I bring salvation - FPC Unleashed
Re: Please help
« Reply #28 on: November 14, 2023, 08:19:38 am »
Ok, do 10101001
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: Please help
« Reply #29 on: November 14, 2023, 07:08:42 pm »
You've all completely lost me.

Bye.

 

TinyPortal © 2005-2018