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
1
vote
3 answers

How to make smoother wave by apply hamming window?

I have try to make the smoother wave (from stock price) but I don't know how to apply it to my wave. import numpy as np wave = [1575.7918235085228, 1574.2183726917613, 1571.9212868430398, 1569.5071067116478, 1568.4249178799716, 1567.4649192116478,…
YONG BAGJNS
  • 501
  • 2
  • 8
  • 21
1
vote
0 answers

SICStus Prolog: FFI slow, how to calculate Hamming weight fast?

When I ran the foreign code sample c1/2, as shown in the SICStus Prolog 4.3.2 manual, and compared its runtime to the corresponding Prolog code Y is X+9, I got strange timing results: p(N, X) :- ( true1G, X is N+9, false ; X is N+9 ). q(N, X) :- (…
repeat
  • 18,496
  • 4
  • 54
  • 166
1
vote
1 answer

Looking for a more efficient pop count given a restriction

The popcount function returns the number of 1's in an input. 0010 1101 has a popcount of 4. Currently, I am using this algorithm to get the popcount: private int PopCount(int x) { x = x - ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x…
Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
1
vote
1 answer

calculate hamming distance and weight in sqlite

Is there a good way to calculate hamming distance and weight in sqlite? It supports bit-wise operators but I want to order results based on hamming weight, and there is no support for bitcount in sqlite. To be more elaborate, let's say I have those…
sivann
  • 2,083
  • 4
  • 29
  • 44
1
vote
2 answers

Matlab: index array by Hamming Weights

a contains indices and their occurrences. Now the indexing needs to be changed with Hamming weight so that indices with equal hamming weight will be summed up. How to do the Hamming weight indexing? Any ready command for this in Matlab? >>…
hhh
  • 50,788
  • 62
  • 179
  • 282
0
votes
0 answers

Formula for the total Hamming weight of the sequence of 1, 2, ..., n

This problem is fairly straightforward if log2(n) is a whole number as we can use a simply use: n * log2(n)/2 however it miscounts when log2(n) isn't a whole number. My intuition is there should be a formula similar to this that works for all n but…
Lucas
  • 106
  • 1
  • 1
  • 7
0
votes
1 answer

Linux Kernel - How do Linux file flags work?

I am currently working on a custom kernel for a project, and one of the things I need is to create a new custom file flag(s), similar to this question: Passing custom flags to "open" in a device driver I have been able to create them, and compile…
Iorpim
  • 167
  • 2
  • 9
0
votes
0 answers

Сalculate the weight of each byte of number x

While learning C++, i decided to get some knowledge of assembly. So i have to count weight of each byte of some number. #define _CRT_SECURE_NO_WARNINGS #include using namespace std; int main() { int x=0; int count = 0; cout…
Nfoth
  • 1
0
votes
0 answers

Assembly on bits

Hi so I need to create a program that will save the amount of on bits in ax to bx. I tried using SHR and SHL and it didnt wokred so well. If you can show me how can I check that using shr and shl I will be greatfull. Thanks
SkyBear
  • 3
  • 5
0
votes
0 answers

Popcnt using inline assembly language in C

A simple implementation of the popcnt function in C: int popcnt(uint64_t x) { int s = 0; for (int i = 0; i < 64; i++) { if ((x << i) & 1 == 1) s++; } return s; } I am using inline assembly language (x86-64) to implement popcnt, int…
0
votes
1 answer

Hamming weight equation in Z3 SMT Sovler

I have a system of equations to solve in which there is some equations of hamming weight. Hamming weight is generally the number of 1's in binary representation of a number. I tried to solve in Z3 SMT Solver, but it outputs an error stating "…
ABCD
  • 7
  • 3
0
votes
0 answers

Optimized way to perform AVX2 VPXOR and popcount in minimum clock cycles

We have to perform bit wise XOR operation on two arrays each containing 5 elements of uint64_t (unsigned long long) and then perform counting (pop count) of 1's. What is the optimized way by using AVX2 256 bit wide YMM registers, AVX2 VPXOR and…
0
votes
3 answers

Need to count number of 1's in binary with assembly

i have task where i should count number of 1's in binary that I set which have odd number then i need to display this on 7 segment display. On the code I wrote a comment where I should do this. I am working with Texas Instruments msp430. I looked at…
Burak
  • 1
  • 1
  • 3
0
votes
1 answer

Enumerate integers by Hamming weight, modulo bit shifting

I need to sample integers from an ordered array described as follows. Let k be a positive integer. All entries are nonnegative integers in [0,2^k) The list starts at 0 All the (increasing) integers with hamming weight 1 modulo bit shifting (i.e.…
0
votes
0 answers

Hamming Weight of Int64

I'd like to ask how the BitMask looks like when I need to apply the hamming weight algoritm on an Int64 to count the set bits. For an Int32 it looks like this: public int HammingWeight(int value) { value = value - ((value >> 1) &…
yq8
  • 145
  • 1
  • 10