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 7994407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:07:24+00:00 2026-06-04T14:07:24+00:00

for(unsigned int h=0; h<ImageBits.iHeight; h++) { for(unsigned int w=0; w<ImageBits.iWidth; w++) { // So

  • 0
 for(unsigned int  h=0; h<ImageBits.iHeight; h++)
  {
        for(unsigned int  w=0; w<ImageBits.iWidth; w++)
        {
              // So in this loop - if our data isn't aligned to 4 bytes, then its been padded
              // in the file so it aligns...so we check for this and skip over the padded 0's
              // Note here, that the data is read in as b,g,r and not rgb as you'd think!
              unsigned char r,g,b;
              fread(&b, 1, 1, fp);
              fread(&g, 1, 1, fp);
              fread(&r, 1, 1, fp);

              ImageBits.pARGB[ w + h*ImageBits.iWidth ] = (r<<16 | g<<8 | b);

        }// End of for loop w

        //If there are any padded bytes - we skip over them here
        if( iNumPaddedBytes != 0 )
        {
              unsigned char skip[4];
              fread(skip, 1, 4 - iNumPaddedBytes, fp);
        }// End of if reading padded bytes

  }// End of for loop h

I do not understand this statement and how does it store the rgb value of the pixel

ImageBits.pARGB[ w + h*ImageBits.iWidth ] = (r<<16 | g<<8 | b);

i did a read up on the << bitwise shift operator but i still do not understand how it works.Can someone help me out here.

  • 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-06-04T14:07:25+00:00Added an answer on June 4, 2026 at 2:07 pm

    Bit shifting moves the bits that make up the value along by the number you specify.

    In this case it’s done with colour values so that you can store multiple 1 byte components (such as RGBA which are in the range 0-255) in a single 4 byte structure such as an int

    Take this byte:

    00000011

    which is equal to 3 in decimal. If we wanted to store the value 3 for the RGB and A channel, we would need to store this value in the int (the int being 32 bits)

    R        G        B        A
    00000011 00000011 00000011 00000011 
    

    As you can see the bits are set in 4 groups of 8, and all equal the value 3, but how do you tell what the R value is when it’s stored this way?

    If you got rid of the G/B/A values, you’d be left with

    00000011 00000000 00000000 00000000

    Which still doesn’t equal 3 – (in fact it’s some massive number – 12884901888 I think)

    In order to get this value into the last byte of the int, you need to shift the bits 24 places to the right. e.g.

    12884901888 >> 24

    Then the bits would look like this:

    00000000 00000000 00000000 00000011

    And you would have your value ‘3’

    Basically it’s just a way of moving bits around in a storage structure so that you can better manipulate the values. Putting the RGBA values into a single value is usually called stuffing the bits

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

Sidebar

Related Questions

unsigned int *pMessageLength, MessageLength; char *pszParsePos; ... //DATA into pszParsePos ... printf(\nMessage Length\nb1: %d\nb2:
Unsigned int into a short and back. Is this possible? How to do it
int plus unsigned int returns an unsigned int. Should it be so? Consider this
const unsigned int omode = cimg::exception_mode(); cimg::exception_mode() = 0; Never see this kinda syntax
Reading from a pipe: unsigned int sample_in = 0; //4 bytes - 32bits, right?
I have a unsigned int that was converted to a signed char like this
I have an unsigned int storing a random number. I need to use this
Relevant code is this: typedef unsigned long int chunk_head; typedef struct malloc_chunk { //
typedef unsigned int Set[10]; Set set1; I am correct in assuming that this creates
This is the code: unsigned int number; FILE* urandom = fopen(/dev/urandom, r); if (urandom)

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.