Comparing binary values in MySQL

后端 未结 3 1014
温柔的废话
温柔的废话 2021-01-19 07:48

Say you have two binary values

001011 
001111

How can you get the number of different bits in MySQ

相关标签:
3条回答
  • 2021-01-19 07:57
    SELECT BIT_COUNT(b'001011' ^ b'001111');
    
    0 讨论(0)
  • 2021-01-19 08:18
    SELECT BIT_COUNT( CONV( '001011', 2, 10 ) ^ CONV( '001111', 2, 10 ) )
    
    0 讨论(0)
  • 2021-01-19 08:24

    It's converting the numbers 1011 and 1111 (base 10) to binary and doing the comparison. If you did:

    SELECT BIT_COUNT(11 ^ 15)
    

    It'd work.

    0 讨论(0)
提交回复
热议问题