Click here to Skip to main content
15,880,392 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralReversing a logical ( OR ) Pin
albert_redditt2-Sep-21 11:31
albert_redditt2-Sep-21 11:31 
GeneralRe: Reversing a logical ( OR ) Pin
PIEBALDconsult2-Sep-21 12:13
mvePIEBALDconsult2-Sep-21 12:13 
GeneralRe: Reversing a logical ( OR ) Pin
Jon McKee2-Sep-21 13:11
professionalJon McKee2-Sep-21 13:11 
GeneralRe: Reversing a logical ( OR ) Pin
Matias Lopez18-Oct-21 11:11
Matias Lopez18-Oct-21 11:11 
GeneralRe: Reversing a logical ( OR ) PinPopular
Rick York2-Sep-21 14:43
mveRick York2-Sep-21 14:43 
GeneralRe: Reversing a logical ( OR ) Pin
jschell5-Sep-21 9:24
jschell5-Sep-21 9:24 
GeneralRe: Reversing a logical ( OR ) Pin
James Curran24-Sep-21 5:53
James Curran24-Sep-21 5:53 
GeneralRe: Reversing a logical ( OR ) Pin
harold aptroot5-Oct-21 21:09
harold aptroot5-Oct-21 21:09 
The formula is correct (though as mentioned it doesn't "undo" the OR, it computes the OR in terms of other operations) and I'll prove it algebraically, starting at the end and deriving that it must be equal to v1 | or_val.
( v1 ^ or_val ) + ( v1 & or_val )
=    (the left and right operands do not "intersect", their bitwise AND is zero, in that case A + B == A | B)
( v1 ^ or_val ) | ( v1 & or_val )
=    (OR distributes over AND)
(v1 ^ or_val | v1) & (v1 ^ or_val | or_val)
=    (A ^ B | B == A | B)
(or_val | v1) & (v1 | or_val)
=    (A AND A == A)
v1 | or_val

GeneralRe: Reversing a logical ( OR ) Pin
Phil Hodgkins5-Oct-21 22:28
Phil Hodgkins5-Oct-21 22:28 
GeneralRe: Reversing a logical ( OR ) Pin
Rob Grainger14-Oct-21 10:06
Rob Grainger14-Oct-21 10:06 
GeneralRe: Reversing a logical ( OR ) Pin
Richard Deeming14-Oct-21 23:17
mveRichard Deeming14-Oct-21 23:17 
GeneralThat's one way to do it Pin
Kent Sharkey17-Aug-21 10:21
staffKent Sharkey17-Aug-21 10:21 
GeneralRe: That's one way to do it PinPopular
Mike Hankey17-Aug-21 10:38
mveMike Hankey17-Aug-21 10:38 
JokeRe: That's one way to do it Pin
PIEBALDconsult17-Aug-21 10:50
mvePIEBALDconsult17-Aug-21 10:50 
GeneralRe: That's one way to do it Pin
Jon McKee17-Aug-21 11:18
professionalJon McKee17-Aug-21 11:18 
GeneralRe: That's one way to do it Pin
den2k885-Oct-21 21:17
professionalden2k885-Oct-21 21:17 
GeneralRe: That's one way to do it Pin
Dan Neely29-Nov-21 3:23
Dan Neely29-Nov-21 3:23 
GeneralRe: That's one way to do it Pin
Jon McKee17-Aug-21 11:10
professionalJon McKee17-Aug-21 11:10 
GeneralRe: That's one way to do it Pin
PIEBALDconsult17-Aug-21 11:14
mvePIEBALDconsult17-Aug-21 11:14 
GeneralRe: That's one way to do it Pin
Jon McKee17-Aug-21 11:23
professionalJon McKee17-Aug-21 11:23 
GeneralRe: That's one way to do it Pin
jsc4218-Aug-21 22:38
professionaljsc4218-Aug-21 22:38 
GeneralRe: That's one way to do it Pin
kalberts17-Aug-21 11:31
kalberts17-Aug-21 11:31 
GeneralRe: That's one way to do it Pin
James Walsh Jr17-Aug-21 13:53
professionalJames Walsh Jr17-Aug-21 13:53 
GeneralRe: That's one way to do it Pin
Brisingr Aerowing17-Aug-21 14:08
professionalBrisingr Aerowing17-Aug-21 14:08 
GeneralRe: That's one way to do it Pin
PIEBALDconsult17-Aug-21 14:43
mvePIEBALDconsult17-Aug-21 14:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.