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 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
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