To expound.
- no need to call pow(), simple multiplying can be faster
The reason for pow is that some take up four bytes, 256 * 256 * 256 * 256. just multiplying will only go up to 2 bytes ... wont it?.
Actually you want to do a bitwise shift.
This also fixes integer overflow problems you may have had with pow() (while using float type), which is the reason you used double in the first place, so that can be removed and replaced by a DWORD.
- reason why you see 4294967295 instead of -1 is that you are multiplying 0xFF * 256 in every loop instead of treating it as -1
smithie’s method is correct at least in this part; you should calculate the value in unsigned form using 0xFF first.
Getting -1 should be done last, through a simple cast to an int or signed dword.
I used double instead of float because float returns 4.294967E+09 which is less understandable to me
It also lost precision; a float (4 bytes) can not accurately display every number that a dword can hold. It would also corrupt your calculations when you went into pow() with a high set of numbers; the floating-point value returned would have been truncated and your final result would be corrupt.
Doubles can handle these calculations without loss in data, but with using bitwise shifts you no longer need to use even them.
It is suggested that you change to DWORD or INT and replace pow() with shifts.
L. Spiro