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

How to find the most significant bit of a signed integer in C

I need to find the most significant bit of signed int N and save it in signBitN. I want to do this using bitwise only operations. Also, how would I make signBitN extend so that all its bits are equal to its significant bit. i.e. if it's significant…
-1
votes
1 answer

Radix sort for non-negative integers (bitwise)

I am trying to learn how to work with bitwise shifts and sorting algorithms, and I am lost. I want to use the binary representation of integers and using bitwise operations to sort the integers using radix sort. I already applied a radix sort using…
-1
votes
1 answer

Get wrong answer in bitwise and on unsigned int on c?

I have two numbers, 2147483648 and 808529920 stored in unsigned int variables but, when I do their bitwise and in C, the answer is supposed to be 1, but I get 0. 808529920 in binary looks like: 110000001100010011000000000000 2147483648 in binary…
-1
votes
1 answer

Fast AND operation on bit arrays

What can be a faster algorithm for doing bitwise AND operation on large bit-arrays? I have implemented bit-array in C++ using a char array. For now, I am iterating over each byte and performing AND operation. void ANDoperation(char* A, char* B){ …
-1
votes
3 answers

C speed of comparison: Equals "==" vs Bitwise and "&"

Suppose I have an integer that is a power of 2, eg. 1024: int a = 1 << 10; //works with any power of 2 no. Now I want to check whether another integer b is the same as a. Which is faster/better (especially on weak embedded systems): if (b == a)…
tobalt
  • 131
  • 5
-1
votes
1 answer

What is if(i | j) and if (i & j) doing in C++

Hello after learning C++ for several months I decided to look at some CPA practice questions and the very first question threw me off with this code. #include using namespace std; int main(void) { int i = 1, j = 2; if(i > j && j > i) …
-1
votes
2 answers

The Perfect Square with BIT WISE AND

How to optimize the solution of counting number of perfect square of the of the contiguous sub arrays when bit wise AND operation is performed on the sub arrays. The Time Complexity should be O(n) or O(n*logn). Here is the naive approach int…
shubham singh
  • 511
  • 1
  • 5
  • 16
-1
votes
2 answers

C# Looking for a more efficient means of storing and comparing lists of true/false values

I have datasets with lists of true/false values. These lists can be of any length, but typically will vary between 5 and 40 items in length in most cases. Within each dataset all lists will be of the same length. For the purposes of this process,…
BBlake
  • 2,388
  • 1
  • 22
  • 31
-1
votes
2 answers

Python: SyntaxError using bitwise function

I am trying to create a basic bitwise function that filters out a certain subset of my data for me. >>>heads=fits.open('datafile.fits') >>>data=heads[1].data Now, I need to mask out data points that are in a certain column and which are set to bit…
hlew528
  • 3
  • 2
-1
votes
2 answers

Bitwise 'AND' operator and its evaluation in a code

I've came across bitwise operators, and they really seem odd to me. Just wanted to get clarifications on two questions that I don't fully understand. The first piece of code is: x = raw_input('Enter a digit: ') print 'x is %s' % ('Even', 'Odd')[x &…
novice
  • 19
  • 1
  • 1
  • 2
-1
votes
1 answer

Bit Masking in a Cache

In C I am attempting to separate an integer address value into the tag bit and the set index bit in a direct mapped cache with 4 sets. I do this so I can compare the correct tags at the line in the correct set of my cache. Here for example the…
Branbron
  • 101
  • 4
  • 12
-1
votes
2 answers

Counting number of one's in a binay number

how does this code works for example input: 5(101) ouput: 2 the function is scanf("%d", &a); while(a) { oneina++; a=a&(a-1); } printf("%d", oneina);
-1
votes
1 answer

PIC assembler and Bitwise AND

Could anyone expain to me how does the bitwise AND operations work? I have following code: CLRF LATC & 0x7F MOVWF LATC & 0x7F What is the purpose of using & 0x7F? What does that change? Update: I know how general bitwise operations works, and I…
Marek
  • 3
  • 2
-2
votes
1 answer

why I am getting 'NaN' for '&' operator?

I am not able to understand why I am getting this "NaN" while performing AND-Bitwise operator for some numbers only? please see pic I attached to understand My issue clearly. 'use strict'; function getMaxLessThanK(n, k) { let toknowNum = []; …
-2
votes
4 answers

Unusual behaviour with booleans in javascript

While working with booleans in javascript, I have noticed an uncertainty: "false" && true //this gives output true false && true //this gives output false Can I somebody explain this behaviour?
Aman Kumayu
  • 381
  • 1
  • 9