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

  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Arithmetic
AI Thread Summary
The discussion explains that the bitwise AND operation between integer variables A (60) and B (13) results in 12. This is demonstrated using their binary representations: A is 0011 1100 and B is 0000 1101. Applying the truth table for the AND operation, the result is calculated as 0000 1100, which equals 12 in decimal. Additionally, the thread briefly mentions other bitwise operations like OR and XOR, providing examples for clarity. Understanding these operations is essential for programming in languages like C and Java.
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top