MATLAB: Bit Flip-Bit Negation

bit flipbit negation

Hi, There is a way to do a single or multiple bit flip. For bit flip i mean the negation of only that bit in a decimal number. for example: bitflip(8,2) = 10 this should mean a negation on second bit of 8. Thank You

Best Answer

bitflip = @(val, n) bitxor(val, 2.^(n-1));