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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:57:37+00:00 2026-05-12T14:57:37+00:00

probably a simple question but I seem to be suffering from programmer’s block. :)

  • 0

probably a simple question but I seem to be suffering from programmer’s block. 🙂

I have three boolean values: A, B, and C. I would like to save the state combination as an unsigned tinyint (max 255) into a database and be able to derive the states from the saved integer.
Even though there are only a limited number of combinations, I would like to avoid hard-coding each state combination to a specific value (something like if A=true and B=true has the value 1).

I tried to assign values to the variables so (A=1, B=2, C=3) and then adding, but I can’t differentiate between A and B being true from i.e. only C being true.

I am stumped but pretty sure that it is possible.
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-12T14:57:38+00:00Added an answer on May 12, 2026 at 2:57 pm

    Binary maths I think. Choose a location that’s a power of 2 (1, 2, 4, 8 etch) then you can use the ‘bitwise and’ operator & to determine the value.
    Say A = 1, B = 2 , C= 4

    00000111 => A B and C => 7

    00000101 => A and C => 5

    00000100 => C => 4

    then to determine them :

    if( val  & 4 ) // same as if (C)
    if( val  & 2 ) // same as if (B)
    if( val  & 1 ) // same as if (A)
    
    if((val  & 4) && (val & 2)  ) // same as if (C and B)
    

    No need for a state table.

    Edit: to reflect comment
    If the tinyint has a maximum value of 255 => you have 8 bits to play with and can store 8 boolean values in there

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

Sidebar

Ask A Question

Stats

  • Questions 191k
  • Answers 191k
  • 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 "If the two operands are not of the same type,… May 12, 2026 at 6:11 pm
  • Editorial Team
    Editorial Team added an answer You could try: $("br").filter(function() { return $(this).css("display") == "none" }) May 12, 2026 at 6:11 pm
  • Editorial Team
    Editorial Team added an answer Unfortunately, no. Not much more I can say, unfortunately. It… May 12, 2026 at 6:11 pm

Related Questions

This is probably a really basic problem but I can't seem to find any
What are some ways that I can query the local machine's specifications (a range
This is a Bad Idea, I know, but... I want to configure log4net programmatically
I've looked through similar questions but I'm still a little perplexed about something that
I am having a bit of a problem with a functor (and it's resultant

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.