i am studying the mysql certification guide. at the Bit Data Type section, it says
a BIT(4) sores 4 bit per value
and that storage requirement for a BIT(n) column is (n+7)/8. i dont understand this part. shldnt a BIT(4) take up just 4 bits of storage?
Actually it's a clumsy way to round up the result. What it means is BIT(1) to BIT(8) take 1 byte, BIT(9) to BIT(16) take 2 bytes, etc... There is no 7 bits overhead. Divide the number of bits by 8 and round up the result. BIT(4) will take 1 byte.
It seems there is an overhead of 7 bits - probably identifying a block of memory as BIT storage.
This 7 bits is added to the number requestedby BIT(n) and the total is divided by 8 to give the number of bytes. The manual defines the (n+7)/8 as BYTES
So 4 bits requires less than 2 bytes. The manual says 'approximately' because it depends whether you talk about whole bytes or fractions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With