I'm converting C++ code to C#
Say I got this in C++
int v5;
v5 = (*(_DWORD *)(v4 + 68) ^ (unsigned __int64)(unsigned int)(*(_DWORD *)(v4 + 56) ^ *(_DWORD *)(v4 + 20))) % 9;
In C# it would be like..
int v5;
v5 = (int)((BitConverter.ToInt32(v4, 68) ^ (ulong)(uint)(BitConverter.ToInt32(v4, 56) ^ BitConverter.ToInt32(v4, 20))) % 9);
But I get errors.. with the (ulong)
, (uint)
Operator '^' cannot be applied to operands of type 'int' and 'ulong'
Should I do
(int)(ulong)(uint)(...)
or what?
Use
BitConvert.ToUInt32
(corresponds to theDWORD
type from Win32 C++ programming) instead ofToInt32
(normally anint
), that should help you lose some of the casts and fix some of the type problems.A faithful conversion should be something like the following, though I don't think it's necessary to have the intermediate cast to
ulong
(Since the 32 most significant bits are ignored when we do the mod 9 anyway and I think they'll always end up as 0):