Are the the following lines equivalent?
and eax, NOT 31
and eax,-32
I found the first line in some code that converts a bitmap image to a file and was just wondering why it was written that way.
I also found the formula in C and it looks like they do it the same exact way too:
int bytes=(((24*bitmap_dx+31)&(~31)/8)*bitmap_dy;
^^^^
Quote from: xoreaxeax on September 21, 2013, 10:39:10 AM
Are the the following lines equivalent?
yes.
See also Two's complement (http://en.wikipedia.org/wiki/Twos_complement)
they are the same, in terms of math
but - slightly different, if you were to want to understand or modify the code, later
i prefer the -32 form :P
as for NOT 31, why not just say 0FFFFFFE0h
i am pretty sure these instructions all code as 3-byte opcodes, no matter how you write it
the end result is....
the length of each line (row) in bitmap image data is always evenly divisable by 4
i.e., if the image data for a line requires 15 bytes, the line data must be 16 bytes in length
it's one of the "rules" for bitmap image data
Look at the binary representations:
PrintLine Bin$(-32)
PrintLine Bin$(not 31, f)
Result:
11111111111111111111111111100000
11111111111111111111111111100000
10987654321098765432109876543210
By the way, and al, not 31 and and al, -32 also do the job (but they might be slower).
yes - i use AND AL,-4, and it seems to work well
int bytes=(((24*bitmap_dx+31)&(~31)/8)*bitmap_dy
seems like the equation is a little over-complicated, to begin with
for a 24-bit image....
(((3 * bitmap_dx) +3) AND -4) * bitmap_dy
you could also use
((3 * (bitmap_dx +1)) AND -4) * bitmap_dy