I am working on a tool in C to count some incoming/outgoing bits, I want to preserve the bits and not lose them by changing to bytes.
In the end I want to display xxxxx bits downloaded/uploaded. I am putting the maximum on 10GB=85899345920bits which needs roughly 35 bits to be represented. I am using a 32 bit OS.
I tried unsigned long and unsigned int but they overloaded.
Any easy way to get the addition process and preserve accuracy?
You could take a bit of a hybrid approach: store the number of bytes into one variable and the number of bits that are extra into another variable. Similar to how POSIX systems return the time since the epoch in both seconds and microseconds:
When you get a transfer of
1505bits, store:This way you can keep track of bits.
Or you could take all the fun out of it and use a
long long.