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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:58:41+00:00 2026-05-25T13:58:41+00:00

I have four integer values (0 – 255) for an ARGB color map. Now

  • 0

I have four integer values (0 – 255) for an ARGB color map.

Now I want to make a unique float or integer of these four integers. Is it possible to do it like the following?

sum  = 4 * 255 + A;
sum += 3 * 255 + R;
sum += 2 * 255 + G;
sum += 1 * 255 + B;

Is the value really unique?

  • 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-25T13:58:42+00:00Added an answer on May 25, 2026 at 1:58 pm

    You are trying to do a base convert or something of that sort. Anyway the logic is like in base converting.
    4 bytes = 32 bit. So 32 bit unsigned integer would do well.

    In this case, you have:

    ARGB = A<<24 + R<<16 + G<<8 + B
    

    it’s like this:
    you have 4 bytes of data, meaning

    xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
    

    where X is either 1 or 0 valued bit. You map them like this:

    AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB
    

    and then all you have to do is to add them, but before that you shift the bits. You shift the A bits to the left, by 8*3 (to be beyond the limits of R, G and B bits), then shift the R bits by 8*2, and so on.

    You end up adding these 32 bit integers:

    AAAAAAAA 00000000 00000000 00000000
    00000000 RRRRRRRR 00000000 00000000
    00000000 00000000 GGGGGGGG 00000000
    00000000 00000000 00000000 BBBBBBBB
    

    Where A, R, G, B can be either 0 or 1, and represent as a whole, the 8 bit value of the channel. Then you simply add them, and obtain the result. Or as DarkDust wrote, use not the + operator, but instead the | (bitwise or) operator, since it should be faster in this particular case.

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

Sidebar

Related Questions

I have four integer values: 1, 2, 3 and 4. Instead of printing the
I have a map (for example, of character to integer). I insert values into
I have four integer numbers a, b, c, d, and integer x ϵ [1,
I have four tables containing exactly the same columns, and want to create a
Hey Guys I have four integer array lists which were created after parsing a
I have four variables of type integer - var tip_1, tip_2, tip_3, tip_4; The
If I have following map: NavigableMap<Integer,String> nmap = new TreeMap<Integer,String>(); nmap.put(3, Three); nmap.put(1, One);
I have a query which returns a single row with four integer columns. select
I have a wxPython ListCtrl with five columns. Four of these hold strings, the
Hi I have question regarding cin and buffer. I want to make a simple

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.