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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:31:51+00:00 2026-06-04T21:31:51+00:00

I want to compute the truth table for an expression(valid logical expression) input by

  • 0

I want to compute the truth table for an expression(valid logical expression) input by the user as a String. Can anybody post an existing solution to this or guide me in doing so??
I am thinking of using a BitArray (of size 2^no. variables) as the output (the truth table). But do not know how to start. Please help me with this.

Ex:-

 p or q or r

Should result as

 False True True True True True True True 

And

 a and b 

Should result as

 False False False True 
  • 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-04T21:31:52+00:00Added an answer on June 4, 2026 at 9:31 pm

    First, you will need to parse the string input to find the variables and the structure of the expression (i.e. what operations are applied to what sub-expressions).

    Once you are done with that, you can represent the state of the variables as a binary integer. Whith this representation you can start from 0 (meaning all variables are false) and increment the integer representation by 1 for each row of the truth table. This way you can account for all possible combinations exactly once.

    Then apply the values of the variables to the expression (subtitute true/false according to the bit value of the integer for the variables in question) and cacluate the value of the expression.

    If you want compact representation of the result, you can just store the expression values for each input combination in a linear collection (e.g. vector) where the index of the output corresponds to the above integer representation of the variable values. If you know what variable maps to which bit of the input, you can re-create the full table any time you need to (e.g. for printing)

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

Sidebar

Related Questions

I want to compute result from this table. I want quantity 1 - quantity2
I want to compute how many times my computer can do counter += 1
I want to compute and count all trigrams of a string in SQL Server.
I have a field that I want to compute based on a string and
I want to compute an md5 hash not of a string, but of an
I want to compute salt for aspnet Membership. private static string CreateSalt(int size){ But
I want to compute the time 4 hours later during the DST transition, either
For use in a rigid body simulation, I want to compute the mass and
I want to ask how to add a computed column in BIRT that compute
I want to compute the minimum size both vertical and horizontal that will contain

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.