mysql [localhost] {msandbox} ((none)) > select length(crc32(3)) * 8, bit_length(crc32(3)); +----------------------+----------------------+ | length(crc32(3)) * 8 | bit_length(crc32(3)) | +----------------------+----------------------+ | 80 | 80 | +----------------------+----------------------+ 1 row in set (0.00 sec)
I have never seen bit_length outside of man pages.
Does it change with a UTF-16 string?
Try using it with a UTF8 string which has some multi-byte characters. LENGTH should return number of characters, BIT_LENGTH would include all the bytes which are used to encode it.
So I would say: Definitely useful.
@Antony:
LENGTH() returns the number of bytes consumed, not the number of characters.
To get the number of characters, you have CHAR_LENGTH().
With non-ascii characters, and on utf8 charset, it will follow that LENGTH(t) > CHAR_LENGTH(t)
(BTW, BIT_LENGTH is still LENGTH*8 in this case)
Have never used it myself, and have never seen it in use.
I have never seen bit_length outside of man pages.