Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4557176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:28:18+00:00 2026-05-21T17:28:18+00:00

I found this source which works quite well, I just want to ask about

  • 0

I found this source which works quite well, I just want to ask about this piece of code which I dont get:

//calculate total size of RGBQUAD scanlines (DWORD aligned)

    bih.biSizeImage = (((bih.biWidth * 3) + 3) & 0xFFFC) * bih.biHeight ;

I get why there is “*3”, but dont get the “+3” and the bitwise AND with FFFC hexa. Could someone explain me why he claculates size of the image this way?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:28:19+00:00Added an answer on May 21, 2026 at 5:28 pm

    If you try that out for various values, you’ll see it’s actually forcing (width * 3) to round up to the smallest multiple of 4 that will contain it. He’s probably doing this to enforce things to be 32-bit aligned.

    Using python:

    >>> f = lambda x: ((x * 3) + 3) & 0xFFFC
    >>> [f(x) for x in range(1, 20)]
    [4, 8, 12, 12, 16, 20, 24, 24, 28, 32, 36, 36, 40, 44, 48, 48, 52, 56, 60]
    

    The following shows the difference between just doing the straight multiplication and rounding upwards towards a multiple of 4

    >>> [(3*x, f(x)) for x in range(1, 8)]
    [(3, 4), (6, 8), (9, 12), (12, 12), (15, 16), (18, 20), (21, 24)]
    

    I’m surprised the code doesn’t actually document this fact. Bit twiddling is a wonderful thing, but it can seem very arbitrary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this macro while digging in the source code of tweejump game.
I am a beginner in C. While reading git's source code, I found this
found this little code snippet that seems to do what i want, but im
This is one usage I found in a open source software.And I don't understant
I found this utility, pytranslate , which translates a variety of languages into each
I have an ogg video which works just fine using the video tag when
I'm building a python application from some source code I've found Here I've managed
I have noticed a number of kernel sources that look like this (found randomly
Found this while reading the Neo4j manual, specifically here , I found the sentence:
Found This: tyty stack, Social Icons not working with Infinite Scrolling on Wordpress I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.