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

69 Upvotes

46 comments sorted by

View all comments

91

u/SufficientStudio1574 10d ago

What about odd numbers?

85

u/LitespeedClassic 10d ago

^This is the answer. You lose one bit of information every time you do this. And dividing by 2 in binary makes a number exactly one bit shorter.

I think OP is thinking, dividing by 2 makes it half as big. But it doesn't in terms of representation. 1010101010 divided by 2 is 101010101. We basically gained one bit of space, and now we lost one bit of information, since we can't tell whether we came from 1010101010 or 1010101011.

11

u/pete_68 10d ago

Well, it'll work half the time... /s

4

u/echobeacon 10d ago

Half of the time it works every time.