private int OffsetToBlockNumber(int offset) {
return (int)(Math.Floor((double)(offset / 0x1000)) - (double)0xc);
}
I’m making a class to read a type of file that is divided into blocks sized 4096 bytes, or 0x1000 in hex. The first block is at 0xC000, so that’s why I’m subtracting 0xC from the result..
Anyway, the problem is that when I tried:
Math.Floor(offset / 0x1000) - 0xC
It said the call is ambiguous between the decimal and double types, so I cast them into doubles, and then the result into an int. It seems pretty dumb to do it this way, so I was hoping someone could shed some light on a better way.
Shifting right 12 is the same as dividing by
0x1000. Your original expression can be expressed as:Although I wonder if you actually meant to subtract
0xcbefore dividing/shifting?