C syntax in DIB image size calculation: ">>" and "~"

C syntax in DIB image size calculation: ">>" and "~"

Post by BabeXX » Fri, 24 Dec 1999 04:00:00


Quote:> C syntax in DIB image size calculation: ">>" and "~"
> ----------------------------------------------------------------
> Would you mind giving me a help to explain the following syntax?

> biSizeImage= ((((biWidth*biBitCount) + 31) & ~31) >>3) * biHeight;

> What is ">>" and "~"?
>> shift bits to right -   x >>3 == x/8

~   nor                           x&~ 31 == ..........00000

Quote:> Why not?
> biSizeImage= (biWidth*biBitCount / 8) * biHeight;

its rounded up, to multiple of 4.

 
 
 

1. C syntax in DIB image size calculation: ">>" and "~"

Vincent...
The symbol >> means shift bits to the right by the right argument number, in this case 3.  This is a binary function, so in binary terms this is what happens... let's say your number is 256, or
100000000 in binary notation.  Shifting the number to the right by 3 would result in 100000, or 32, or in human terms a division of the number by 2 to the 3rd, or 8, if you were shifting right by 4 you would effectively be dividing by 2 to the 4th, or 16.  

The symbol ~ is the ones complement operator... this simply inverts all binary bits.  in the case of 31 which is 00000000000000000000000000011111 in binary, the number becomes 11111111111111111111111111100000, or 4,294,967,246 in base 10.  

The bottom line is this whole algoritm simply aligns the number on a DWORD, or 4 byte boundary.  All of the results should be evenly divisible by 4.

Ex:  ImageWidth  = 101, Bitcount = 24

((((101 * 24) + 31) & ~31)>>3) =
 ( (2455 & ~31) >> 3) =
    (2455 & 4,294,967,246) >> 3 =
        2432 >> 3 =
            304

304 is evenly divisible by 4, or DWORD aligned.

Rick

2. Cannot open search page after SP1 for XP installation

3. |||||"""" How do I lock a CDROM """"|||||

4. VISUAL BASIC OCX

5. WANTED """ NT 3.51 Training Videos """" WANTED

6. How to hide a directory?

7. "Reply" doesn't always indent with ">"

8. gemini d-16 scanner

9. param name="ActivateActiveXControls" value="-1">

10. Folders: "My ..." versus "<named> folders"

11. wmp copy to cd """ error """

12. FLIC ====>>> MPEG ... need "DISPLAY"

13. "New Message", "Send Page" & "Send a Link" from IE6