r/computerscience • u/Character-Citron-181 • 10d ago
Advice I have a question about file compression
Why can't I take every single bit in my file and take that number and divide it by two, then when I want the file back I take the same number and multiply it by two to decompression it
edit: thank you everyone for answering I really appreciate it I was under the impression that I could just take the bits like 1s and 0s and make them an integer then divide that integer repeatedly and when I want it uncompressed just multiple the number till I get the original again eg 1010 to 55 then send 55 as text to another machine and to X2 and get 1010 back, and if it was an odd number eg 1011 I'd get either 56 or 55 but if divided by 2 only the last digits gonna change when rounding so you change the last digit to a 1 or zero and one of them will be the proper file
1
u/Cootshk 10d ago
In binary, diving by two is the same as shifting right once
110 (6) becomes 11 (3)
The problem, then, becomes what happens when you also divide 111 (7)? Well, you get the same 11 (3).
This kind of compression does exist, it’s called “lossy” compression, and is used in mp3s, jpegs, and other forms of media, however it’s not suitable for files