Questions tagged [hammingweight]

The Hamming weight of a positive integer is the count of one bits in its binary representation.

The Hamming weight of a positive integer is the count of one bits in its binary representation.

A common synonym is "population count", hence the common function name popcount.

69 questions
0
votes
1 answer

How to calculate the Hamming weight for a vector?

I am trying to calculate the Hamming weight of a vector in Matlab. function Hamming_weight (vet_dec) Ham_Weight = sum(dec2bin(vet_dec) == '1') endfunction The vector is: Hamming_weight ([208 15 217 252 128 35 50 252 209 120…
user6594048
0
votes
2 answers

What is the fastest way to compute a random 64bit neighbor with given hamming-distance of 2 and same hammingweight?

Regardless of similar questions already answered here, I want to know the following: What is the fastest way to compute a random 64bit neighbor with given hamming-distance of 2 and same hammingweight? I have come up with the following somewhat…
0
votes
1 answer

HAKMEM Hamming Weight bithack has a bug, any way to save it?

;if A is a 9 bit quantity, B gets number of 1's (Schroeppel) IMUL A,[1001001001] ;4 copies AND A,[42104210421] ;every 4th bit IDIVI A,17 ;casting out 15.'s in hexadecimal This function seems to need a 33rd bit to count the bit in the 32s…
OmnipotentEntity
  • 16,531
  • 6
  • 62
  • 96
0
votes
4 answers

How to use assembly POPCNT instruction when running on a 32 bits Ubuntu

For a particular project I'm sticked with gcc and a 32 bits 12.04 LTS Ubuntu running on i7 Core supporting up to AVX SIMD instructions. Due to the 32 bits OS, I apparently can't use the AVX instructions running on 256 bits. I have access to SSE4.2…
0
votes
2 answers

Hamming weight of an interval

My task is to calculate number of 1-bits of interval [1,10^16]. Loop is obviously unusable for this case, and I've heard there exists an algorithm for this. Can anyone help? More generally, an algorithm for number of 1-bits in an interval [1,n]…
0
votes
1 answer

How to efficiently determine whether the Hamming Weight of an integer is exactly one?

Given a 32 or 64 bit integer in C++03, what is an efficient way to determine whether there is exactly one bit set or not? (e.g. value is exactly one of 1, 2, 4, 8, 16, 32, etc.) Are there any builtins to C++ 03 library (or if not then C++11) that…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
-2
votes
1 answer

Optimization of the condition in the if-statement

Well I know that the title makes almost no sense but I could not find a better one to explain my question here. So I've just started doing challenges on LeetCode and I am on the very first steps for now. But one situation confused me. So I was…
-2
votes
1 answer

Assembly language program to count number of 1's in binary number

Can someone please help I stuck since few day on this problem. I want to count numbers of 1's in binary value of 2 decimal/hexa. But I am getting incorrect results. Here a code below: .386 //32-bit processor .model small, stdcall ExitProcess…
GoAkshay
  • 80
  • 8
-3
votes
2 answers

How to create a sub array of given array of binary numbers based on number of 1's in Ruby?

Example: Here is binary numbers array: a = [001, 010, 100, 011, 101, 110, 111, 1000, 1001, 1010] I want output like below: [ [ 001, 010, 100, 1000 ], [ 011, 101, 110, 1001, 1010 ], [ 111 ] ] Can anybody help me how to achieve it in ruby?
asha
  • 139
  • 1
  • 6
1 2 3 4
5