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

  • Home
  • SEARCH
  • 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 119197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:36:54+00:00 2026-05-11T03:36:54+00:00

In code, I sometimes see people specify constants in hex format like this: const

  • 0

In code, I sometimes see people specify constants in hex format like this:

const int has_nukes        = 0x0001; const int has_bio_weapons  = 0x0002; const int has_chem_weapons = 0x0004; // ... int arsenal = has_nukes | has_bio_weapons | has_chem_weapons; // all of them if(arsenal &= has_bio_weapons){   std::cout << 'BIO!!' } 

But it doesn’t make sense to me to use the hex format here. Is there a way to do it directly in binary? Something like this:

const int has_nukes        = 0b00000000000000000000000000000001; const int has_bio_weapons  = 0b00000000000000000000000000000010; const int has_chem_weapons = 0b00000000000000000000000000000100; // ... 

I know the C/C++ compilers won’t compile this, but there must be a workaround? Is it possible in other languages like Java?

  • 1 1 Answer
  • 3 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. 2026-05-11T03:36:55+00:00Added an answer on May 11, 2026 at 3:36 am

    I’d use a bit shift operator:

    const int has_nukes        = 1<<0; const int has_bio_weapons  = 1<<1; const int has_chem_weapons = 1<<2; // ... int dangerous_mask = has_nukes | has_bio_weapons | has_chem_weapons; bool is_dangerous = (country->flags & dangerous_mask) == dangerous_mask; 

    It is even better than flood of 0’s.

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

Sidebar

Ask A Question

Stats

  • Questions 200k
  • Answers 200k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think I've got it, I tried using this, p… May 12, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer Your removeData DataTable needs to have the same columns/fields as… May 12, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer You use the toggle value to the height parameter. You… May 12, 2026 at 7:56 pm

Related Questions

Suppose Object1 needs information from Object2. I'll say it's in an Object2 property, but
I often have code based on a specific well defined algorithm. This gets well
I was watching Rob Connerys webcasts on the MVCStoreFront App, and I noticed he
Following up on my previous question on the enduring properties of a book on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.