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
SUMMARY

The discussion centers on the bitwise AND operation between two integer variables, A and B, where A is 60 and B is 13. The result of the operation A & B equals 12, which is derived from their binary representations: A (0011 1100) and B (0000 1101). The truth table for the AND operation confirms that the resulting binary value is 0000 1100, which translates to the decimal value of 12. The discussion also briefly touches on related bitwise operations such as OR (|) and XOR (^).

PREREQUISITES
  • Understanding of binary number representation
  • Familiarity with bitwise operations in programming languages like C and Java
  • Knowledge of truth tables for logical operations
  • Basic understanding of integer data types
NEXT STEPS
  • Study the implementation of bitwise operations in C and Java
  • Learn about binary arithmetic and its applications in programming
  • Explore the differences between bitwise AND, OR, and XOR operations
  • Investigate how bitwise operations can optimize performance in algorithms
USEFUL FOR

This discussion is beneficial for programmers, computer science students, and anyone interested in understanding bitwise arithmetic and its applications in coding and algorithm optimization.

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