Questions tagged [bitcount]

42 questions
1
vote
3 answers

C++ Fast and Efficient way to perform bit_count and AND operation on 40 byte array

In my project I need to AND two binary array of size 40 bytes(320 bits) and then compute set bit count in C++. I found some algorithms to do this but I want to know what is the fastest way of implementing it in c++. I mean what c++ data type would…
Hamid Bazargani
  • 847
  • 1
  • 15
  • 30
1
vote
1 answer

Fast bit counting in range

I need to find the algorithm solving this problem : find the sum of all positive bits in numbers in range [x,y]. Warning : x and y can be very big ( from 1 to 10^20 ). Thanks for help.
John Smith
  • 19
  • 2
0
votes
2 answers

count number of set bits in integer

i am studing different methods about bit counting ,or population count methods fopr given integer, during this days,i was trying to figure out how following algorithms works pop(x)=-sum(x<
user466534
0
votes
0 answers

message output not working due to BitCount and Length being zero

I'm kind of new to CAPL. Today I am trying to use the output function for sending UDS messages on CAN, using a simple code below: UdsReq.dir = 1; UdsReq.byte(0) = 0x02; UdsReq.byte(1) = 0x10; UdsReq.byte(2) = 0x03; …
0
votes
1 answer

32 bit builtin population count for clang counts long long integer c++

I was using the __builtin_popcount with clang compiler and I needed to count a 64 bit number (unsigned long long or uint64_t). From looking it up, __builtin_popcount counts 16 bits, __builtin_popcountl counts 32 bits, and __builtin_popcountll counts…
BanjoMan
  • 93
  • 5
0
votes
0 answers

Calculate Hamming Distance in SQLite

I wanted to compare multiple images and retrieve the most similar image using hamming distance. The only problem is SQLite which is the most commonly available database in mobile platform doesn't support those important function needed by hamming…
0
votes
3 answers

Trouble doing a bitwise xor + bit_count in mysql

I am trying to perform a comparison on hash values (hexadecimal strings of 16 characters). I have a MYSQL table that stores those values with a phash VARCHAR(16) column. This is what I am trying to do: SELECT phash, bit_count(phash ^…
David
  • 1,898
  • 2
  • 14
  • 32
0
votes
0 answers

redis bitcount example not working

I was playing with redis and tried the bitcount example: http://redis.io/commands/bitcount . 127.0.0.1:6379> SET mykey "foobar" OK 127.0.0.1:6379> BITCOUNT mykey (error) ERR unknown command 'BITCOUNT' my redis version are as follows: mohit@mohit:~$…
Mohit
  • 891
  • 10
  • 25
0
votes
2 answers

Mysql convert varchar binary representation field to binary to do hamming distance calculation with bit_count

I've a db table with a varchar(64) field to store PHashing data, as 64 chars (1's and 0's ascii characters). I need to calculate hamming distance with a test hasta, and it seems that the most efficient way to do is using mysql bit_count function.…
sucotronic
  • 1,504
  • 9
  • 20
0
votes
1 answer

Bitwise - bitCount's formula meaning?

here is the copy of the code from Integer.bitCount(int i) I understand all the operators but don't understand how those magic numbers can find out the count! can anyone explain that to me? I can see the pattern (1,2,4,8,16 & 0x5,0x3,0x0f). …
Jaxox
  • 960
  • 4
  • 14
  • 25
0
votes
1 answer

Using bitcount command in redis

I set a key to 0 and get the bitcount using the below command in redis set result 0 bitcount result I get the output to be 2 instead of 0. When i set the result to any other number and print the bitcount I get the correct number of set bits with…
Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105
-1
votes
2 answers

Finding how many bits it takes to represent a 2's complement using only bitwise functions

We can assume an int is 32 bits in 2's compliment The only Legal operators are: ! ~ & ^ | + << >> At this point i am using brute force int a=0x01; x=(x+1)>>1; //(have tried with just x instead of x+1 as well) a = a+(!(!x)); ... with the last 2…
Gadesxion
  • 391
  • 2
  • 6
  • 18
1 2
3