我有一个选项设置,掩码applicationReserved = 0x0F000000
指示4位范围。由此,我想生成可能的值0x01000000
,0x02000000
,0x03000000
,...
我已经提出了一些可能的解决方案,但我怀疑可能有更明确的表达方式:
applicationReserved & -applicationReserved
applicationReserved & -applicationReserved << 1
...
或
applicationReserved / 15
applicationReserved / 15 * 2
...
答案 0 :(得分:0)
我认为这与您在评论中描述的内容最为接近:
let x = 0x0F0000000
var offset = 0
while offset < 63 && (x & (1 << offset)) == 0 { offset += 1 }
for i in 0..<16 {
let y = i << offset
print(String(y, radix: 16))
}