12-30-2020 02:49 PM
Hello Friends,
I have a question regarding the working of OR function when both it's inputs are numbers. I tried myself and found that, when both my inputs are same, then I get the output as the input value. Ex. input 1= 10 and input 2=10 then I get answer as 10.
When I give different inputs, then I get the addition of the inputs as the answer. Ex. input 1= 20 and input 2=10 then I get answer as 30.
But when I give higher number as a input, then I get completely different result (which is not the addition of numbers).
Ex. input 1= 1000 and input 2=10 then I get answer as 1002.
Could anyone please explain me how exactly OR function here is computing the output?
Thanks in advance! 🙂
Solved! Go to Solution.
12-30-2020 03:00 PM - edited 12-30-2020 03:03 PM
Hi ajinkya,
@ajinkya007 wrote:
When I give different inputs, then I get the addition of the inputs as the answer. Ex. input 1= 20 and input 2=10 then I get answer as 30.
This is only partially correct: OR is considered a "boolean addition"! (AND is the "boolean multiplication"…)
@ajinkya007 wrote:
But when I give higher number as a input, then I get completely different result (which is not the addition of numbers). Ex. input 1= 1000 and input 2=10 then I get answer as 1002.
Could anyone please explain me how exactly OR function here is computing the output?
You are working with (hopefully) integer numbers, which consist of several bits (aka booleans). Those bits are ORed…
1000d = 1111101000b
0010d = 0000001010b
OR = 1111101010b
12-30-2020 05:59 PM
@ajinkya007 wrote:
Could anyone please explain me how exactly OR function here is computing the output?
As GerdW already stated, when OR with integers, it is a bit-wise OR. Similar for AND, XOR, etc.
12-30-2020 06:07 PM - edited 12-31-2020 06:58 PM
Both AND and OR operate bitwise on integers. (All this is explained in the help) Bitwise operation have nothing to do with addition or multiplication at all..
OR: The new number is an integer where all bit are TRUE where at least one of the inputs has a bit set.
AND: The new number is where only the bits are TRUE that are true in both inputs.
Assuming 16 bit numbers (using one of your examples):
A = b0000001111101000 (1000 in decimal)
B = b0000000000000010 (2 in decimal)
A OR B = b0000001111101010 (1000 OR 2, i.e. 1002 in decimal)
A AND B = b0000000000000000 (1000 AND 2, i.e. 0 in decimal)