[Solved] How can I set the least significant bit of an integer in C [duplicate]


To set bit 0 to one, use

int_var | 1

To reset bit 0 to zero, use

int_var & ~1

The operation in your example doesn’t seem consistent:

10000011    
10000010    & ~1
00000001    xor

00001011    
00001011    nop
00000000    xor

01110011   
01110010    & ~1
00000001    xor

11101100    
11101101    & ~1
00000001    xor

11110101    
11110100    & ~1
00000001    xor

01001011    
01001010    & ~1
00000001    xor

01001010
01001010    nop
00000000    xor

01110100
01110100    nop
00000000    xor

solved How can I set the least significant bit of an integer in C [duplicate]