Revision ded3ae24-f972-4aa2-a05d-de865f63de7f - Code Golf Stack Exchange
#JavaScript (ES6) 92
Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:
- calc p3wrong|p2wrong|p1wrong (line 2,3,4)
- use it as a bit mask to flip the incorrect bit (line 1),
- then return just the data bits (last line)
<!-- language: lang-js -->
F=w=>(w^=128>>(
((w/4^w/2^w^w/8)&1)*4|
((w/16^w/2^w^w/32)&1)*2|
((w/16^w/4^w^w/64)&1)
))&7|w/2&8
**Test** In Frefox/FireBug console
;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2)))
*Output*
["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]