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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:32:20+00:00 2026-05-13T05:32:20+00:00

I got a problem I was hoping someone could help me figure out! I

  • 0

I got a problem I was hoping someone could help me figure out!

I have a string with a hexadecimal number = '0x00000000' which means:

0x01000000 = apple  
0x00010000 = orange  
0x00000100 = banana   

All combinations with those are possible. i.e., 0x01010000 = apple & orange

How can I from my string determine what fruit it is? I made a dictionary with all the combinations and then comparing to that, and it works! But I am wondering about a nicer way of doing it.

  • 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-13T05:32:20+00:00Added an answer on May 13, 2026 at 5:32 am

    Convert your string to an integer, by using the int() built-in function and specifying a base:

    >>> int('0x01010000',16)
    16842752
    

    Now, you have a standard integer representing a bitset. use &, | and any other bitwise operator to test individual bits.

    >>> value  = int('0x01010000',16)
    >>> apple  = 0x01000000
    >>> orange = 0x00010000
    >>> banana = 0x00000100
    >>> bool(value & apple) # tests if apple is part of the value
    True
    >>> value |= banana     # adds the banana flag to the value
    >>> value &= ~orange    # removes the orange flag from the value
    

    Now, if you need to convert back to your string:

    >>> hex(value)
    '0x1000100'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

got a small little problem I'm hoping someone can help me with. I have
i got problem with my code and hopefully someone able to figure it out.
I am hoping that someone can help me with a problem I've got at
I was hoping someone can point out what my problem could be. I am
I have two problems with Nginx I am hoping someone could help me with.
got a little problem im hoping someone can enlighten me on. Trying to serialise
Alright, hoping someone can help. I've got a page used to search for employees.
Good Morning Everyone, I am hoping that someone can help me with a problem.
I'm a bit stumped and I'm hoping someone can help me. I've got a
Please can someone help sort a noob out? I've posted this problem on various

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.