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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:04:30+00:00 2026-05-27T12:04:30+00:00

I have a value DB of 3 bytes (DB_1, DB_2, DB_3). I need to

  • 0

I have a value DB of 3 bytes (DB_1, DB_2, DB_3).
I need to check DB_3 for specific bits. For example I have to see if
DB_3 == 11X0XXXX
Where only bit 4, 6 and 7 should be checked. Bits marked as X can take any value and should not be checked. I am not familiar with Bit operations in Java and glad for any help!
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-27T12:04:31+00:00Added an answer on May 27, 2026 at 12:04 pm

    You can use a bitwise AND (& in Java) to accomplish the masking to specific bits (the mask is the second line and will only let those bits of the first line through where the mask has a 1 [marked with arrows below the calculation]):

      11101001
    & 11010000
    ----------
      11000000
      ↑↑ ↑
    

    You’ll retain exactly those bits that were 1 in both operands, so essentially you set all those bits to 0 that you are not interested in.

    So you just need to do

    if (DB_3 & 0xD0 == 0xC0) { ... }
    

    0xD0 is the hexadecimal form of 208 which is 11010000 in binary and you want to know whether it matches 0xC0 which is 192, or 11000000. You’ll know that all the bits you don’t care about (the Xes in your question) are already zero at this point due to the bitwise AND.


    ETA (2011-12-14 14:24): Apparently Java 7 has binary integer literals, so you can do

    if (DB_3 & 0b11010000 == 0b11000000) { ... }
    

    which makes the mask more readily apparent. Thanks, Glenn.

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

Sidebar

Related Questions

I have a value __int64 that is a 64-bit FILETIME value. FILETIME has a
I have string value and Type of some variable (For example int and 32
For example I have a value of 103.33 I want to put 100 to
I have a value like this: Foo Bar Another Value something else What regex
Doesn't value have to return toString() to be able to call value.toString()? When do
I have the value of the epoch time like say 123456789, now I want
Say I have the value: -5 that represents a TimeZone (GMT-5). How can I
I have a Double which could have a value from around 0.000001 to 1,000,000,000.000
Currently I have a value prompt added to my report (with UI selected as
If I have the value foo , and a HashMap<String> ftw for which ftw.containsValue(foo)

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.