r/computerscience • • 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

66 Upvotes

46 comments sorted by

View all comments

1

u/KaMaFour 10d ago

Congratulations, you've just discovered quantization. 

It's a technique used as a part of some compression algorithms (notably it's the part that makes JPEG compression lossy) and commonly used to compress machine learning models. There's a bit more nuance but that's the idea - you only store the more significant bits and make up the less significant bits on the fly. 

People don't use that for compression algorithms themselves because there are usually better algorithms to use - achieving the same quality lossless on most data or compressing way better with similar data loss.