Not sure what you're expecting from the C++ code. But when I use this:
#include <iostream>
using namespace std;
#define bitShift(_val) \
((unsigned __int64)(((((unsigned __int64)_val) & 0xff00000000000000ull) >> 56) | \
((((unsigned __int64)_val) & 0x00ff000000000000ull) >> 40) | \
((((unsigned __int64)_val) & 0x0000ff0000000000ull) >> 24) | \
((((unsigned __int64)_val) & 0x000000ff00000000ull) >> 8 ) | \
((((unsigned __int64)_val) & 0x00000000ff000000ull) << 8 ) | \
((((unsigned __int64)_val) & 0x0000000000ff0000ull) << 24) | \
((((unsigned __int64)_val) & 0x000000000000ff00ull) << 40) | \
((((unsigned __int64)_val) & 0x00000000000000ffull) << 56)))
int main()
{
unsigned __int64 test = bitShift(25);
return 0;
}
I get the exact same return value(1801439850948198400 || &H1900000000000000) as this:
Dim result As ULong = SwapBits(25)
Public Function SwapBits(ByVal uvalue As UInt64) As UInt64
Dim swapped As UInt64 = ((((uvalue) And &HFF00000000000000UL) >> 56) Or _
(((uvalue) And &HFF000000000000UL) >> 40) Or _
(((uvalue) And &HFF0000000000UL) >> 24) Or _
(((uvalue) And &HFF00000000UL) >> 8) Or _
(((uvalue) And &HFF000000UL) << 8) Or _
(((uvalue) And &HFF0000UL) << 24) Or _
(((uvalue) And &HFF00UL) << 40) Or _
(((uvalue) And &HFFUL) << 56))
Return swapped
End Function
I don't have much experience in C++, care to share what this is doing:
u8 counter[16];
*(u64 *)(counter + 0) = bitShift(i);
*(u64 *)(counter + 8) = 0;
basically that section of code increments the first 8 bytes of counter by 1 each iteration 0f i
, starting with the right most byte and expanding left for each carryover. For instance, if the counter reaches 999 counter[7] will hold 231(&HE7) and counter[6] 3(&H3) which when you look at the whole array gives, &H000000000003E7 which equals 999 decimal.