Questions tagged [bitwise-and]

Anything related to the bitwise-AND operation, i.e. a binary operation carried out on two integer operands whose result is obtained performing the logical AND between each pair of corresponding bits in the operands.

Anything related to the bitwise-AND operation, i.e. a binary operation carried out on two integer operands whose result is obtained performing the logical AND between each pair of corresponding bits in the operands.

317 questions
-2
votes
4 answers

What does the 'and' instruction do to the operands in assembly language?

What does the 'and' instruction do in assembly language? I was told that it checks the bit order of the operands and sets the 1s to true and anything else to false, but I don't know what it actually does or what effect it has on the code.
user548010
  • 21
  • 1
  • 1
  • 1
-2
votes
2 answers

Java print binary number using bit-wise operator

Hi I am creating a method that will take a number and print it along with its binary representation. The problems is that my method prints all 0's for any positive number, and all 1's for any negative number private static void display( int number…
user69514
  • 26,935
  • 59
  • 154
  • 188
-2
votes
2 answers

sizeof operator fails on bitwise & in C

Thanks for your response, the %zu specifiers work okay with the sizeof operator, size gets printed okay and x and y values also. But when I changed all of those specifiers to %lld, which should print actual x and y values(as they are long long), it…
Prakhar
  • 25
  • 1
  • 7
-3
votes
0 answers

Why those bitwise operators fail?

According to this Bit masking (javascript): how to check ALL flags I tried this js but I failed. Do I miss something? var port = 17; // this fails. function checkPort() { if ((0x1 & port) == 0x1) console.log("1"); if ((0x10 & port) == 0x10)…
krg
  • 1
  • 3
-3
votes
3 answers

What's the purpose of & in Java?

So, I was following a pacman tutorial and the coder uses & not &&. He doesn't explain what it does though. I searched it up and it says that unlike &&, & checks both statements. That makes sense. But the coder doesn't use it in a comparison…
-3
votes
1 answer

Java equivalent of & (single ampersand) in if statement, like in C?

So after learning both C and Java, Java doesn't have the capability of Bitwise-Anding in an if-statement between two values. int x = 1011; int y = 0110; // 0010 if (x % y) { printf("EXAMPLE") } I know I'm missing something. I think it's…
-3
votes
1 answer

Bitwise and doesn't work on unsigned long

I have this code where I use "bitwise and" (&) to try and change x: #include int main (void){ unsigned long x = 0; printf("x = %lu\n", x); x &= 1; printf("x = %lu\n", x); return 0; } I compile and execute the code…
71GA
  • 1,132
  • 6
  • 36
  • 69
-3
votes
3 answers

What is the meaning of this operation

So we got this piece of code on a test and I had zero idea what is the meaning and how it works. unsigned int a = 1, b = 2, c; and then c = a&b || a&&b; The question was: What is the value of c. Answer was 1. Can somebody explain what is happening…
DomHofman
  • 29
  • 4
-3
votes
1 answer

OpenCV assertion error on bitwise_and method

import cv2 import numpy as np img = cv2.imread("Yash.jpeg") blank = np.zeros(img.shape[:2]) cv2.imshow("YASH", img) cv2.imshow("Blank", blank) mask = cv2.circle(blank, (img.shape[1]//2, img.shape[0]//2), 150, 255, -1) cv2.imshow("Mask",…
Yash
  • 11
  • 6
-3
votes
1 answer

Bitwise AND operation not clear

I'm trying to understand the bitwise AND operator in C; it works until I put a 0 in front of 177. I'm doing this by hand to make sure I understand what the compiler is doing #include main () { printf ("%d\n", 1999 & 177); …
-3
votes
1 answer

Bitwise operation gives incorrect result

I'm fairly new to bitwise operations so I apologize ahead of time if my question seems poorly worded or not fit for stackoverflow. Recently, I've been toying with the bitwise AND operation by simply just printing out the results of expressions using…
Chris Gong
  • 8,031
  • 4
  • 30
  • 51
-3
votes
3 answers

functioning of bitwise and

This question was asked in an interview, can someone tell what does the following code do? It gives output 15 for 150, 3 for 160, 15 for 15. What mathematical operation is it performing on 'n'. int foo(int n) { int t,count=0; t=n; …
Vanya
  • 361
  • 5
  • 16
-4
votes
1 answer

Number of pairs of a and b given w

Given two statements 1) w + a = b 2) a & b = 0 (bitwise and) Find the number of pairs of a and b given w. Can someone please help me how should i solve this problem.
-4
votes
1 answer

Bitwise And for Int[] One Liner

Can anyone help me find a method of taking the bitwise and (&) function of every element in an int[] in a single line? For example, [1,3,8,9] would be 1&3&8&9. I am trying to make a constructor for a class that calls another constructor so I can't…
Sam H
  • 91
  • 1
  • 9
-4
votes
2 answers

Difference between ANDing with bitwise shift and hex values

If I want to set bit 2 of a value to 0, what's the difference between the two following: value = value & (1<<2); value = value & 0x2;
Brocodile
  • 67
  • 11
1 2 3
21
22