Back to my-Tool.com
Google
  
my-Tool.com: Be Wise Bitwise - Performs bitwise related tasks such as search boolean expression or show the truth table etc. - Truth Seeker
IP Address
MaximaPHP
Regexp Tester
Mathematics
String and Text
Word Domain
Games
Code Tester
Internet Codes
Networking
Date and Time
Be Wise Bitwise
Ranqueen
Q & A
About me
Forum
Open Source Facts
AdManner Free
Classified Ads
Indonesian
Japanese
TrafficSwarm: free advertisement
   
Truth Seeker   Show the Truth   

Truth Seeker

Searchs for boolean expressions for a set of results in the truth table.



Sometimes you may have a long boolean expression in your code whose variables are repeated several times. This type of boolean expression will be more efficient and elegant if could be reduced or simplified to a simpler boolean expression which gives the same result.

For example, the long boolean expression

result = a & (b | c) ^ a & ~b | ~c ;

has variables a, b, and c repeated 2 times each, so we could expect to replace it by a simpler boolean expression such as

result = a & b | ~c ;

While Karnaugh map (aka Veitch diagram) would help you understanding your expression well, this tool might help you save your time if you're lucky :). Firstly, construct the truth table for your boolean expression using Show the Truth, and search the simpler one for your result below.

Seek for: Operators:
Variable number:
Expression length: With negation


Note that the precedence of bitwise operators in javascript is ~, &, ^, |. Therefore the expression a|~b&c^d would mean a|(((~b)&c))^d) or logically a || (((!b) && c) XOR d) etc. However javascript doesn't support logical XOR, so you could simulate it with a XOR b = (a || b) && !(a && b).

Example

I had written this tool when worked on another much simpler tool, HTML Encoder. In the heart of encoding function it will check if a character has an entry in the HTML code table, return it if any or else the character itself. Moreover if the character is space, user can choose either to encode it or not. This needs the following branch to do the job:

return spc ? (html ? html : c) : (c==' ' ? c : (html ? html : c)) ;

This branch can be thought as boolean expression with the truth table something like

spchtmlc==' 'result
1111(html)
1101(html)
1010(c)
1000(c)
0110(c)
0101(html)
0010(c)
0000(c)

Now I want to replace the branch above with the simpler boolean expression which gives the exact same result. All I have to do is searching for the result '11000100' with 3 variables. I got no result when the expression length was set to 3, but with the length of 4 the following expressions are found:
  • (b & c & ~a) ^ b
  • (b & ~c) | (a & b)
Since javascript doesn't have logical XOR I used the last expression to replace my branch as below:

return ((html && !(c==' ')) | (spc && html)) ? html : c ;

Most of the visitors who used this tool also used
IP - 国 (16.7%), ビーワイズビット (16.7%), Source (16.7%)
source
©2006 my-Tool.com