Binary 0x01010101如何等效于1<&书信电报;24+;1<&书信电报;16+;1<&书信电报;8+;1.
问题给出了在给定数字中用于计算1个数的说明。在解释时,他写道 0x01010101=(1) 即0x01010101Binary 0x01010101如何等效于1<&书信电报;24+;1<&书信电报;16+;1<&书信电报;8+;1.,binary,bit-manipulation,bitwise-operators,bit-shift,Binary,Bit Manipulation,Bitwise Operators,Bit Shift,问题给出了在给定数字中用于计算1个数的说明。在解释时,他写道 0x01010101=(1) 即0x01010101 即0x01010101。让我们从总数开始: Hex: 0x01010101 Decimal: 16843009 Binary: 1000000010000000100000001 现在分别看它们。从1开始让我们从总数开始: Hex: 0x01010101 Decimal: 16843009 Binary: 1000000010000000100000001
即0x01010101。让我们从总数开始:
Hex: 0x01010101
Decimal: 16843009
Binary: 1000000010000000100000001
现在分别看它们。从
1开始让我们从总数开始:
Hex: 0x01010101
Decimal: 16843009
Binary: 1000000010000000100000001
现在分别看一下它们。从1开始,你首先需要了解你首先需要了解
Calculation: 1 << 24
Decimal: 16777216
Binary: 1000000000000000000000000
// ^ 25th position because 1 was shifted 24 times to the left
Calculation: 1 << 16
Decimal: 65536
Binary: 0000000010000000000000000
// ^ 17th position because 1 was shifted 16 times to the left
Calculation: 1 << 8
Decimal: 256
Binary: 0000000000000000100000000
// ^ 9th position because 1 was shifted 8 times to the left
1000000000000000000000000 = 1 << 24
0000000010000000000000000 = 1 << 16
0000000000000000100000000 = 1 << 8
+ 0000000000000000000000001 = 1
|-------|-------|-------|
1000000010000000100000001 = 16843009
1 << 8 = 0b100000000 = 256 = 0x100
1 << 16 = 0b10000000000000000 = 65536 = 0x10000
(1 << 8) + (1 << 16) = 0x10100
0b1000000010000000100000001
^ ^ ^ ^
bit #24 bit #16 bit #8 bit #0