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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:14:52+00:00 2026-06-09T14:14:52+00:00

Possible Duplicate: Good tutorials on Bitwise operations in Java Are the &, |, ^

  • 0

Possible Duplicate:
Good tutorials on Bitwise operations in Java
Are the &, |, ^ bitwise operators or logical operators?

Code as below:

int rgb[] = new int[] {     
(argb >> 16) & 0xff, //red     
(argb >>  8) & 0xff, //green     
(argb      ) & 0xff  //blue 
}; 

I saw a code which is getting RGB value from a INT value, the operations are as above, but I never see such operation before, I want to find more information about what are they and what can they do, The symbol >> and & and 0xff.

So, what do you all address them in Java?

  • 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-09T14:14:53+00:00Added an answer on June 9, 2026 at 2:14 pm

    Further explanation of the bit arithmetic. Let’s assume the int bits look as follows:

    00000000 10101010 01010101 11011011
    unused   red      green    blue
    

    To get the int value for blue, you want all bits other than the lower 8 turned off. The easy way to do this is with a bitwise and. 0xff can also be written as 0x000000ff, which will set the upper 24 bits to 0, and only turn on the bits in the lower 8 which are already set to 1.

    argb & 0xff ==> 00000000 00000000 00000000 11011011
                                               blue
    
    argb >> 8 ==> 00000000 00000000 10101010 01010101 
                                    red      green
    (argb >> 8) & 0xff ==> 00000000 00000000 00000000 01010101 
                                                      green
    
    argb >> 16 ==> 00000000 00000000 00000000 10101010
                                              red
    (argb >> 16) & 0xff ==> 00000000 00000000 00000000 10101010
                                                       red
    

    even thought the & 0xff on the red value seems unecessary, there’s no guarantee the caller might not have set some of the high order unused bits, so you want to be safe and turn all of them off.

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

Sidebar

Related Questions

Possible Duplicate: Java : Is there a good natural language processing library Can anybody
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: When is it good (if ever) to scrap production code and start
Possible Duplicate: The Definitive C Book Guide and List Good open source code for
Possible Duplicate: Are static inner classes a good idea or poor design? Java supports
Possible Duplicate: Visual C++ debugger visualizer? Are there any good tutorials on customizing the
Possible Duplicate: Good Java graph algorithm library? Is there a complete library in Java
Possible Duplicate: Are there any good reasons for using hex over decimal for RGB
Possible Duplicate: What good is JSLint if jQuery fails the validation http://code.jquery.com/jquery-1.4.4.js Go to
Possible Duplicate: A Java API to generate Java source files Is there a good

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.