|
albert_redditt wrote: I was told that there's no way to undo an OR as it loses value in the output..
That is correct.
Boolean algebra is implemented in programming languages but it still originates from that branch of mathematics.
If you have a value '1' there is no way you will ever be able to tell which of the following statements it originated from.
1 | 1
1 | 0
0 | 1
Because of that you cannot do that you cannot, in a programming language, recover the original values from a value that was created by oring other values together.
|
|
|
|
|
To reverse a OR operation, given on something like
A | B = C
solve for B knowing only A & C.
For example:
6 | B = 7
Given that, B could be 1 or 3 or 5 or 7. Any of those would work in the equation, and there is no way to know which it was.
Truth,
James
|
|
|
|
|
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
|
|
|
|
|
It uses the value you are trying to find to find the value you are trying to find. No point to it.
E.g. for X OR 9 = 11, use it to find the value of X.
|
|
|
|
|
I suspect the person telling you that meant there is no mathematical inverse to the OR operator - which means that the input of a function (or operator) must be reconstructable from the input to that function. In this sense, OR definitely has no inverse.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Rob Grainger wrote: the input of a function (or operator) must be reconstructable from the input to that function
That's trivial. It's reconstructing it from the output that's difficult.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
GitHub - samuelmarina/is-even[^]
Quote: This is a 100% serious project, and it is made to help the community.
A brief excerpt:
function isEven(number) {
if(number === 1) return false;
else if(number === 2) return true;
else if(number === 3) return false;
else if(number === 4) return true;
else if(number === 5) return false;
else if(number === 6) return true;
else if(number === 7) return false;
They're up to 1,000,001 now. Help them grow!
TTFN - Kent
|
|
|
|
|
I could while away the hours
Conferrin' with the flowers,
Consulting with the rain;
And my head I'd be a scratchin'
While my thoughts are busy hatchin'
If I only had a brain.
The less you need, the more you have.
Even a blind squirrel gets a nut...occasionally.
JaxCoder.com
|
|
|
|
|
Only works with base-10 ?
Surely it would be better written recursively.
modified 17-Aug-21 16:57pm.
|
|
|
|
|
I... what?! I thought you were joking for a second but there actually is a definition for even and odd in generic bases. In even bases it's the last-digit test - odd is odd, even is even; in odd bases it's a test of the sum of all digits - odd is odd, even is even. That makes complete sense; it's just not something I've ever considered
|
|
|
|
|
Ckuf me backwards with a shovel, it's the first time I hear this.
GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
PIEBALDconsult wrote: Only works with base-10 ?
You just need to add conversion functions and call them first.
function hexToDec(number) {
if (number === 1) return 1;
else if (number === 2) return 2;
else if (number === A) return 10;
else if (number === B) return 11;
}
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
You left out the glorious sister project:
It is also important to know if a number is odd, so additionally I created this other package @samuelmarina/is-odd
Spoiler: It's not just function isOdd(x) { return !isEven(x); } 
|
|
|
|
|
function isOdd(x) { return isEven(x-1); } ?
function isOdd(x) { return isEven(~x); } ?
|
|
|
|
|
Your sanity only wishes those were the case
Also that second one is clever.
|
|
|
|
|
PIEBALDconsult wrote: function isOdd(x) { return isEven(x-1); } The sad thing is that that wouldn't work when testing against '1' as that would be testing to see if 0 was even and their isEven does not have a test for 0.
|
|
|
|
|
I grew up with classmates named Odd and Even (which are not unusual boy's names around here). There was never any problem keeping them apart.
|
|
|
|
|
Oh. My. Word. 
|
|
|
|
|
42 MEGABYTES OF JAVASCRIPT?!
Someone needs their head checked!
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Maybe they'll add a few icons later.
|
|
|
|
|
Brisingr Aerowing wrote: 42 MEGABYTES OF JAVASCRIPT?!
Meh. It'll get lost in the framework(s) downloaded with it.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
|
Don't waste my time, hahaha! 
|
|
|
|
|
They have forgotten about negative numbers 
|
|
|
|
|
And 0 . Is 0 even or odd? How can we know when that code is lacking the answer to this most important question?
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|