Learn the Basics of Bitwise Arithmetic: A&B = 12 (Integer Variables A=60, B=13)

  • Context: MHB 
  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Arithmetic
Click For Summary

Discussion Overview

The discussion centers around the operation of bitwise arithmetic, specifically the bitwise AND operation between two integer variables A and B, where A is 60 and B is 13. Participants explore the binary representations of these integers and the resulting output of the operation.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • Some participants assert that A & B results in 12, questioning the reasoning behind this outcome.
  • Participants provide the binary representation of A as 0011 1100 and B as 0000 1101.
  • One participant expresses confusion about the result, stating they obtained 01001001, seeking clarification on how this relates to 12.
  • Another participant introduces a truth table for the AND operation, indicating that the result of the operation should be 0000 1100.
  • Additional context is provided regarding the use of the bitwise AND operator in programming languages like C and Java, with examples of other bitwise operations such as OR and XOR.

Areas of Agreement / Disagreement

Participants do not reach a consensus, as there is confusion regarding the binary results and interpretations of the bitwise operation. Multiple viewpoints and interpretations are presented without resolution.

Contextual Notes

There are unresolved aspects regarding the binary calculations and the interpretation of the results, particularly in relation to the confusion expressed by participants about the output of the bitwise AND operation.

tmt1
Messages
230
Reaction score
0
"Assume integer variable A holds 60 and variable B holds 13 then:A&B will give 12"

Why is this?
 
Technology news on Phys.org
tmt said:
"Assume integer variable A holds 60 and variable B holds 13 then:A&B will give 12"

Why is this?

Write the binary represetation of $A$ and $B$ and then add them.
For example, the binary representation of $A$ is $0011 1100$.
 
evinda said:
Write the binary represetation of $A$ and $B$ and then add them.
For example, the binary representation of $A$ is $0011 1100$.

I get 01001001 how is this 12?
 
tmt said:
I get 01001001 how is this 12?

You have to use this truth table for &:

$$\begin{bmatrix}
p & q & p \& q \\
0 & 0 & 0\\
0 & 1 & 0 \\
1 & 1 & 1\\
1 & 0 &0
\end{bmatrix}$$

Then, the result will be $0000 1100$. (Nerd)
 
In C, Java and other languages, & is the bitwise and of the integer operands. So for example, 6 & 4 is 110 & 100 = 100 = 4. Similarly | is the bitwise or operator. So 6 | 4 = 110 | 100 = 110 = 6. Similarly ^ is the bitwise exclusive or operator. So 6 ^ 4 = 010 = 2.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
5
Views
3K
  • · Replies 45 ·
2
Replies
45
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 80 ·
3
Replies
80
Views
8K