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
4
votes
1 answer

Java Bitwise "&" on integers

I have the following: int a = 10001000; int b = 10000000; I want the following output: (a&b) = 10000000; But my problem is that java converts to binary before using the "&" operation, and I'd really like to be able to use this on integers in…
Fancypants753
  • 429
  • 1
  • 6
  • 19
4
votes
4 answers

Why and 1 ( &1) bitwise operation always return 0 or 1

I just started learning about bit wise operation and want to ask why and 1 ( &1) bitwise operation always return 0 or 1 .
4
votes
1 answer

How to implement this using the bitwise & (and)?

For a program I am writing to connect to a scanner with three output trays (pockets) I need to make use of an SDK. After a call to the SDK I receive an int that represents the status of the pockets. To determine this "pocket" status the following is…
Gecko
  • 1,333
  • 1
  • 14
  • 26
4
votes
3 answers

Bitwise and in PHP

I am very new face to PHP. I read that dechex(255) will give the corresponding hex value ff in PHP. I need the hex value of -105. I tried dechex(-105) and got the result as ffffff97. But I just only want 97 to do some kind of stuffs. In Java I know…
Arshad
  • 41
  • 2
4
votes
1 answer

tracking multiple objects by color OpenCV 2.x

Currently i am trying to track multiple objects by color. I've based on documentation code. import cv2 import numpy as np cap = cv2.VideoCapture(0) while(1): # Take each frame _, frame = cap.read() # Convert BGR to HSV hsv =…
alejandro zuleta
  • 13,962
  • 3
  • 28
  • 48
4
votes
3 answers

C++: Assigning the result of bitwise AND to a bool

I have the following loop in C++, compiled with g++ 4.1.2: while(1) { int status = getStatus(); bool firstOk = status & 0x1; bool secondOk = status & 0x2; if(firstOk != m_firstOk) { logStatus(1, firstOk); m_firstOk =…
Víctor Fernández
  • 1,754
  • 1
  • 16
  • 15
3
votes
2 answers

Extracting rightmost N bits of a double in C

I have some natural big number in double. I need to get 30 rightmost bits of it (of integral part). If it was integer the operation was: var & 0x3FFFFFFF I can implement some functions for the purpose, but I need some simple solution. Is there…
nik
  • 435
  • 1
  • 6
  • 14
3
votes
2 answers

bitand : keyword vs function in C++

I've tried using the alternative bitwise operator 'bitand' in below simple code. Its appears that I can use bitand as a keyword as well as a function in Visual C++, both yielding different results, can anyone explain this discrepancy? int d = 12, e…
ianupkale
  • 33
  • 4
3
votes
0 answers

Is x & 1 always a correct way to determine if a number is odd?

I've heard from many answers that x & 1 == 1 will determine if a number is odd (which makes sense); but I never see this in practice (x % 2 != 0 is usually used instead) Are there any potential issues with using the bitwise and, or is x % 2 != 0…
Reid Moffat
  • 322
  • 1
  • 3
  • 16
3
votes
4 answers

What does the bitwise AND operator & do in this code snippet?

Please help to solve this problem and explain the logic. I don't know how the & operator is working here. void main() { int a = -1; static int count; while (a) { count++; a &= a - 1; } printf("%d", count); }
user302593
  • 123
  • 2
  • 13
3
votes
5 answers

Equality operator versus bitwise AND operator usage

In C language, I often see if statements in such form: #define STATUS 0x000A UINT16 InterruptStatus; if (InterruptStatus & STATUS) { } If I had this statement, would it be any different in processing time or any other…
newb7777
  • 517
  • 5
  • 22
3
votes
1 answer

Why does bitwise-AND with 0xffff achieve in (uint32_t)(((f - (int)f) * 65536.0f))&0xffff?

This question is regarding a code example in Section 7.4 of Beej's Guide to Network Programming. Here is the code example. uint32_t htonf(float f) { uint32_t p; uint32_t sign; if (f < 0) { sign = 1; f = -f; } else { sign = 0; } …
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
3
votes
1 answer

Why is the bitwise AND of two of the same value producing a different value?

I have noticed a weird behaviour using bitwise AND operator in JS: console.log((0xd41ddb80 & 0xd41ddb80).toString(16)) The result is -2be22480, but I was expecting 0xd41ddb80 What can be the cause of this behaviour?
assaf
  • 210
  • 2
  • 9
3
votes
1 answer

Python GetLogicalDrives Bitwise AND

i have some questions about the following code. from win32 import win32file drives = [] drivebits=win32file.GetLogicalDrives() for d in range(1,26): mask=1 << d if drivebits & mask: drname='%c:\\' % chr(ord('A')+d) …
MeteHan
  • 289
  • 2
  • 16
3
votes
3 answers

How does bitwise-and operator work on objects in javascript?

I'm working on an open source project and stumbled over bitwise operators. I do understand the principles and also that javascript evaluates non-zero integer values to true (correct me here if I'm wrong; found this statement in an accepted answer in…
Bardock
  • 65
  • 7
1 2
3
21 22