Something I discovered doing logic

  • Context: High School 
  • Thread starter Thread starter vin300
  • Start date Start date
  • Tags Tags
    Logic
Click For Summary

Discussion Overview

The discussion revolves around a proposed relationship between bitwise operations (AND and OR) on two numbers and their arithmetic sum. Participants explore the implications of this relationship, provide examples, and clarify the operations involved.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant describes a process involving AND and OR operations on two numbers, claiming that the sum of these results equals the sum of the original numbers.
  • Another participant requests clarification and examples of the AND and OR operations in base 10.
  • A different participant suggests that the terms "X and Y" and "X or Y" could be interpreted as min(X,Y) and max(X,Y), respectively, proposing that this interpretation leads to the same conclusion about their sum.
  • A later reply reiterates the original claim and provides a detailed explanation of how bitwise operations work, including an example with specific numbers (P=5 and Q=6) to illustrate the process and results.

Areas of Agreement / Disagreement

Participants express varying interpretations of the operations and their implications. While some agree on the relationship between the operations and the arithmetic sum, others question the initial claim and propose alternative interpretations. The discussion remains unresolved regarding the broader implications of these operations.

Contextual Notes

The discussion includes assumptions about the nature of the numbers involved (e.g., whether they are positive integers) and the specific definitions of the operations, which may affect the validity of the claims made.

vin300
Messages
602
Reaction score
4
I haven't known about a law that says so. Step 1: using two numbers in any format: binary, octa, hexa, do an AND operation. Step 2: Perform OR operation on the same numbers. Step 3: Add the results of step 1 and 2 numerically. The result comes out to be the same as the sum of original numbers.
 
Physics news on Phys.org
Give an example to explain what you mean by performing an "AND" and an "OR" operation on two numbers. Show an example in ordinary base 10 representation.
 
Hmm I wonder if "X and Y" simply means min(X,Y) and "X or Y" means max(X,Y), when applied to numbers. If so, what vin300 has discovered is just that min(X,Y)+max(X,Y)=X+Y, which is easy to see.
 
vin300 said:
I haven't known about a law that says so. Step 1: using two numbers in any format: binary, octa, hexa, do an AND operation. Step 2: Perform OR operation on the same numbers. Step 3: Add the results of step 1 and 2 numerically. The result comes out to be the same as the sum of original numbers.

What you "discovered" is that P&Q added to P|Q is equal to P+Q, right?

Here's a short explanation of what's really happening. Using the bitwise operator "&" for the logical operator "AND" and the bitwise operator "|" for the logical operator "OR", evaluating the expression P&Q basically creates a binary number with "1" at each position where both numbers have a "1" and puts zeros elsewhere; the expression P|Q does the same thing but puts a "1" at each position where at least one of the two numbers has a "1" and also puts zeros elsewhere. So when you add both expressions P|Q and P&Q, you're basically adding P and Q and the remainders, which gives you P+Q. This works under binary arithmetic since the only possible operations we have for addition are:
  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 0, and carry 1 to the next more significant bit, i.e. in this direction ←
In other words, when you evaluate P&Q or P|Q, every position where P and Q both had zeros will remain zero; likewise, every position where at least P or Q or both had "1" will remain the same. Since in the last case one event is included in the other, this assures you under the arithmetic rules we agreed on that adding P&Q and P|Q is equivalent to add P and Q.

Here is an example with P=5 and Q=6:
Code:
Expression     Result     Binary Description
P              5          00000101
Q              6          00000110
P & Q          4          00000101 & 00000110 = 00000100
P | Q          7          00000101 | 00000110 = 00000111

When you add P&Q and P|Q, you have:
Code:
      1
  00000100 = P & Q
+ 00000111 = P | Q
----------
  00001011 = (P & Q) + (P | Q)
And when you add P and Q, you have:
Code:
      1
  00000101 = P
+ 00000110 = Q
----------
  00001011 = P + Q
We can see that both expressions are equal. Of course the mathematical representation of bitwise operations can get messier depending of what we're using, e.g. if P and Q are not positive and/or integers, but that's the general procedure used to handle these operations, and basically every programming language that I know of does that.
 
  • Like
Likes   Reactions: micromass and berkeman

Similar threads

  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 18 ·
Replies
18
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
2K
  • · Replies 45 ·
2
Replies
45
Views
6K
  • · Replies 15 ·
Replies
15
Views
4K