- Nov 12, 2023
- 2
- 1
- 36
Hello everybody. I have problem: I need to write program but iam not programmer. Full algorithm of actions:
Program read any file and check if it not has .cmprs extension, if it not has it check it size, if it equal to 8192 bit then read it in binary and check if it not consist of only zeroes or ones. If all checks is true then do subroutines 1, else check if it has .cmprs extension and it size is smaller than 8192 bit, if true then do subroutines 2, else print “error” and HALT.
Subroutines 1: open file as binary text string, ie all 1 and 0 now become text character. Delete from that string from left all zeroes and one one, that one included, if we get empty string use exemption rule. Declare variable N that equal to number of bits of resulting string. Declare variable D10 that equal to that string value in base10, ignoring all zeroes from left, example string 0101 has integer value 5, string 101 also has integer value 5. Declare variable A that equal to N + D10. Now add 1 to A, ie A:=A+1. Now declare variable B that equal to Floor from log(A) base 2. Now declare variable R that equal to R:=A – 2^B. 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, example B=3 R=2: firstly get string from R = 10, then add so much zeroes, in our case only one, and final answer 010. Now save that string with name of original file, add low dash and old extension letters, and .cmprs extension and HALT. Exemption rule: just write 0 in new string, save that string with name of original file, add low dash and old extension letters, and .cmprs extension and HALT.
Subroutines 2: : open file as binary text string. Declare variable N that equal to number of bits of resulting string. Declare variable D10 that equal to that string value in base10, ignoring all zeroes from left, example string 0101 has integer value 5, string 101 also has integer value 5. Declare variable A that equal to N + D10. Now subtract 1 from A, ie A:=A-1. If A turn out to be 1 then use exemption rule. Now declare variable B that equal to Floor from log(A) base 2. Now declare variable R that equal to R:=A – 2^B. 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. Now add to that string one one from left, and add even further to left as much zeroes it needed to make overall string size equal to 8192. Now save that string as binary file under old file name, removing .cmprs extension from it and replace low dash with dot, ie if for example old name was music_mp3.cmprs now it become music.mp3 and HALT. Exemption rule: just write 1 in new string and as much 0 needed to make overall size equal to 8192, now save that string as binary file under old file name, removing .cmprs extension from it and replace low dash with dot and HALT.
If you interested in context and want to know what this program does let me know.
Program read any file and check if it not has .cmprs extension, if it not has it check it size, if it equal to 8192 bit then read it in binary and check if it not consist of only zeroes or ones. If all checks is true then do subroutines 1, else check if it has .cmprs extension and it size is smaller than 8192 bit, if true then do subroutines 2, else print “error” and HALT.
Subroutines 1: open file as binary text string, ie all 1 and 0 now become text character. Delete from that string from left all zeroes and one one, that one included, if we get empty string use exemption rule. Declare variable N that equal to number of bits of resulting string. Declare variable D10 that equal to that string value in base10, ignoring all zeroes from left, example string 0101 has integer value 5, string 101 also has integer value 5. Declare variable A that equal to N + D10. Now add 1 to A, ie A:=A+1. Now declare variable B that equal to Floor from log(A) base 2. Now declare variable R that equal to R:=A – 2^B. 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, example B=3 R=2: firstly get string from R = 10, then add so much zeroes, in our case only one, and final answer 010. Now save that string with name of original file, add low dash and old extension letters, and .cmprs extension and HALT. Exemption rule: just write 0 in new string, save that string with name of original file, add low dash and old extension letters, and .cmprs extension and HALT.
Subroutines 2: : open file as binary text string. Declare variable N that equal to number of bits of resulting string. Declare variable D10 that equal to that string value in base10, ignoring all zeroes from left, example string 0101 has integer value 5, string 101 also has integer value 5. Declare variable A that equal to N + D10. Now subtract 1 from A, ie A:=A-1. If A turn out to be 1 then use exemption rule. Now declare variable B that equal to Floor from log(A) base 2. Now declare variable R that equal to R:=A – 2^B. 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. Now add to that string one one from left, and add even further to left as much zeroes it needed to make overall string size equal to 8192. Now save that string as binary file under old file name, removing .cmprs extension from it and replace low dash with dot, ie if for example old name was music_mp3.cmprs now it become music.mp3 and HALT. Exemption rule: just write 1 in new string and as much 0 needed to make overall size equal to 8192, now save that string as binary file under old file name, removing .cmprs extension from it and replace low dash with dot and HALT.
If you interested in context and want to know what this program does let me know.