Is BIT_LENGTH() useful?

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)

6 thoughts on “Is BIT_LENGTH() useful?

  1. 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.

  2. @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)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.