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
3
votes
2 answers

Bitwise operation performance, how to improve

I have a simple task: determine how many bytes is necessary to encode some number (byte array length) to byte array and encode final value (implement this article: Encoded Length and Value Bytes). Originally I wrote a quick method that accomplish…
Crypt32
  • 12,850
  • 2
  • 41
  • 70
3
votes
2 answers

How does Bitwise AND interact with boolean values?

I have come across a piece of code that I can't wrap my head around: public void Connect() { if (!(!string.IsNullOrEmpty(_vpnConnectionName) & !string.IsNullOrEmpty(_ipToPing))) { return; } GetConnected(); } I've researched…
Chris Schiffhauer
  • 17,102
  • 15
  • 79
  • 88
3
votes
6 answers

bitwise shifts, unsigned chars

Can anyone explain verbosely what this accomplishes? Im trying to learn c and am having a hard time wrapping my head around it. void tonet_short(uint8_t *p, unsigned short s) { p[0] = (s >> 8) & 0xff; p[1] = s & 0xff; } void tonet_long(uint8_t…
mylegfeelsfunny
  • 507
  • 1
  • 8
  • 20
3
votes
2 answers

How to AND byte array in Java?

So I was wondering if/how one might use the AND operation on a byte array in Java? I've seen samples of how to use the AND operation with ints like so: int bitmask = 0x000F; int val = 0x2222; // prints "2" System.out.println(val & bitmask); But…
This 0ne Pr0grammer
  • 2,632
  • 14
  • 57
  • 81
3
votes
3 answers

Bitwise AND with non-booleans

In the following Java program I cannot understand what this line does: wert = (wert * mult + inkr) & 0x7FFFFFFFL; I understand what the bitwise operators do in conditions, but there are principally two numbers (the hexadecimal is the maximum value…
Maxim Zubarev
  • 2,403
  • 2
  • 29
  • 48
2
votes
1 answer

Find the number of pairs of natural numbers from l to r which Bitwise AND is equal to 0

Given l and r, find the number of pairs of natural numbers from l to r which Bitwise AND is equal to 0. Limits : 1 <= l <= r <= 10^9 r - l <= 10^6 I could only write a brute force. Does anyone have an idea how to solve this task? The range size is…
2
votes
2 answers

what the meaning of (a&b)>>c in this systemc code?

when I read SYSTEMC code,I find a function return int like this: static inline int rp_get_busaccess_response(struct rp_pkt *pkt) { return (pkt->busaccess_ext_base.attributes & RP_BUS_RESP_MASK) >> …
celia
  • 25
  • 5
2
votes
3 answers

A Problem I faced using Bitwise Operators in C (HackerRank)

HackerRank Bitwise Operators In this challenge, you will use logical bitwise operators. All data is stored in its binary representation. The logical operators, and C language, use 1 to represent true and 0 to represent false. The logical operators…
2
votes
1 answer

Bitwise OR operation with 0b transform a given number in negative

I need to perform certain operations with bitwise operators, let's say we have this 40 bit unsigned integer: 1071698660929 when I apply to it a OR operator and an unsigned right shift operator I got this negative integer Input: (1071698660929 >>> 0)…
2
votes
1 answer

Bitwise & operator in Snowflake?

I'm stuck with Snowflake about bitwise operators. In MySql it's allowed to use this syntax: Flag & 1024 > 0 I'd like to make the same filtering in the where clause with Snowflake but I've found only these function on the…
2
votes
1 answer

Java - &0xff gives bits from 8 to 31 as 1's

I have a problem while doing the AND operator using 0xff. public Pixel(int x, int y, int p) { this.x = x; this.y = y; pixelValue = p; A = (byte) ((p>>24) & 0xff); R = (byte) ((p>>16) & 0xff); R = (byte) (R&0xff); G =…
2
votes
2 answers

Help with bitwise operations

I want to doublecheck some of my logic against a 3rd party function that I am using and I'm not sure if I've got the bitwise logic figured out correctly or not. Can someone give me a range of values for the variable 'intValue' in each scenario that…
snappymcsnap
  • 2,050
  • 2
  • 29
  • 53
2
votes
5 answers

Bitwise & over 32 bits

#include #include int main() { unsigned long long a = 9223372036854775808; // a = 2^63 a = a & ~1; printf("%llu\n", a); printf("%d, %lld", INT_MAX, LLONG_MAX); } Output 9223372036854775808 2147483647,…
op ol
  • 705
  • 4
  • 11
2
votes
1 answer

How to find the 32-bit of a number

Can I ask how to find the 32-bit version of a number as I want to work around with numbers with the bitwise AND operator in JavaScript. It stated that the numbers perform bitwise operations in 32bit version. Second question is it in JavaScript…
dramasea
  • 3,370
  • 16
  • 49
  • 77
2
votes
2 answers

Why is the & 1 and + '0' is needed to display the binary number?

I got this code here to print the binary of a decimal, if I ran this function with argument as 3, it would print 0000 0011, which is right, I understand that >> will shift the binary to the right 7 to 0 to display the binary, but I do not understand…
Astoach167
  • 91
  • 1
  • 7