在SQL中将整数转换为二进制位

5
我有一个整数字段,需要将它分成位(Bits)以适应SQL(Firebird)。每个整数字节应该是一个新的字段。例如:
Integer field: 7 = 00000111

Bit 1 field1: 1  
Bit 2 field2: 1  
Bit 3 field3: 1  
Bit 4 Field4: 0
Bit 5 Field5: 0
Bit 6 Field6: 0
Bit 7 Field7: 0
Bit 8 Field8: 0

有人知道如何在 Firebird 中实现这一点吗?
1个回答

3
使用 BIN_AND 函数:
SELECT 
   bin_and(field, 1) as bit1, 
   bin_and(field, 2) as bit2, 
   bin_and(field, 4) as bit3,
   bin_and(field, 8) as bit4,
   ... 
FROM T

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接