0

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.

Lea Hayes
  • 62,536
  • 16
  • 62
  • 111
Thomas
  • 4,030
  • 4
  • 40
  • 79

2 Answers2

4

Use some bit twiddling:

long mask = 0;

// For each bit that is set, given its position (0-63):
mask |= 1 << position;
Jon
  • 428,835
  • 81
  • 738
  • 806
3

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?

Aniket Inge
  • 25,375
  • 5
  • 50
  • 78