Question

I'm trying to create a hashing function for images in order to find similar ones from a database. The hash is simply a series of bits (101110010) where each bit stands for one pixel. As there are about 60 pixels for each image I assume it would be best to save this as an UInt64.

Now, when looping through each pixel and calculating each bit, how can I concatenate those and save them as a UInt64?

Thanks for you help.

Was it helpful?

Solution

Use some bit twiddling:

long mask = 0;

// For each bit that is set, given its position (0-63):
mask |= 1 << position;

OTHER TIPS

You use bitwise operators like this:

ulong it1 = 0;
ubyte b1 = 0x24;
ubyte b2 = 0x36;
...
it1 = (b1 << 48) | (b2 << 40) | (b3 << 32) .. ; 

Alternatively you can use the BitConvert.Uint64() function to quickly convert a byte array to int64. But are you sure the target is of 8bytes long?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top