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

  • MHB
  • Thread starter tmt1
  • Start date
  • Tags
    Arithmetic
In summary, when using the bitwise operator &, the binary representation of A and B is 01001001, and the result will be 00001100 or 12 in decimal. This is because in the truth table, when both operands are 1, the result is 1. In programming languages, & is used for bitwise and, | for bitwise or, and ^ for bitwise exclusive or. Therefore, A&B gives 12 because it is the result of adding the binary representation of A and B using the & operator.
  • #1
tmt1
234
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
  • #2
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$.
 
  • #3
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?
 
  • #4
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)
 
  • #5
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.
 

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

1. What is bitwise arithmetic?

Bitwise arithmetic is a type of mathematical operation that is performed on individual bits or binary digits within a number. It involves manipulating these bits using logical operators such as AND, OR, XOR, and NOT to perform various operations.

2. What does A&B = 12 mean?

A&B = 12 means that the result of performing a bitwise AND operation on two integer variables, A and B, is equal to the decimal value of 12.

3. What are integer variables?

Integer variables are variables that can store whole numbers without any decimal points. In the context of bitwise arithmetic, they are used to represent binary numbers and perform logical operations on their individual bits.

4. How do you perform the bitwise AND operation?

To perform the bitwise AND operation, you first convert the given numbers into binary form. Then, you compare the corresponding bits from each number and if both are 1, the result will be 1. Otherwise, the result will be 0. For example, A=60 in binary is 111100 and B=13 in binary is 1101. Performing A&B will result in 1100, which is equal to 12 in decimal form.

5. What is the purpose of learning bitwise arithmetic?

Bitwise arithmetic is commonly used in low-level programming, such as in embedded systems and device drivers. It allows for efficient manipulation of binary data and can also be used for tasks such as data encryption and compression. Understanding bitwise arithmetic is important for anyone working with computer systems and programming at a low level.

Similar threads

Replies
4
Views
420
  • Programming and Computer Science
Replies
17
Views
1K
  • Precalculus Mathematics Homework Help
Replies
8
Views
593
Replies
6
Views
1K
  • General Math
Replies
11
Views
1K
  • Precalculus Mathematics Homework Help
Replies
1
Views
694
  • Precalculus Mathematics Homework Help
Replies
7
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
752
  • Quantum Interpretations and Foundations
2
Replies
45
Views
4K
  • Calculus and Beyond Homework Help
Replies
24
Views
2K
Back
Top