5.0

5.0 | 2 ratings Rate this file 23 downloads (last 30 days) File Size: 6.05 KB File ID: #2787

Boolean Algebra Toolbox , ver. 2.2

by Rasmus Anthin

 

27 Nov 2002 (Updated 03 Dec 2002)

No BSD License  

Generate nbc and gray code, boolean evaluation and display truth-table. The "bool"-class for conveni

Download Now | Watch this File

File Information
Description

Boolean Algebra Toolbox is a small set of functions for easy generation of boolean nbc and gray sequences for sets of boolean variables.
[X1 X2...]=NBC(N) will generate a table of Natural Binary Code where the output is a set of bool-objects.
[X1 X2 X3]=NBC(3) yields:

» [x1 x2 x3]=nbc(3)

x1 =

     0101 0101

x2 =

     0011 0011

x3 =

     0000 1111

and BGRAY(3) yields:

» [x1 x2 x3]=grayc(3)

x1 =

     0110 0110

x2 =

     0011 1100

x3 =

     0000 1111

The constructor for the bool-class works as this:

» x=bool([1 inf 0 -1 0 nan])

x =

     1101 01

of course, the constructor can also have a bool object as an argument.

B2H(X) is a function which converts a binary vector to hex string (length(X)=2^n is required).

The operators used are
+ : or
| : or
* : and
& : and
~ : not
' : not
/ : xor

you can use inequalities as well:
< > <= >= == ~=

some functions used by the bool class:

b2d : "bool" to decimal
b2h : "bool" to hex
display : display object
double : convert to double array
flip : flip the entire boolean object string
flip4 : flips the overall nibble position
flip4i : flips the bit positions for each nibble
flip8 : same as flip4 but for bytes
flip8i : same as flip4i but for bytes
horzcat : bit string concatenation, works with mixed objects (as [0 x1 1 nan x2])
length : length of the bit-string/bool-object
size : size of object in bits, nibbles, bytes, words, etc... depending on structure.
subsasgn : assign with indicies
subsref : pick out bits from the object string with indicies (subscripted reference).

Last but not least, the truth-table function which displays the truth-table for a boolean function with its set of variables. For instance:

» [x1 x2 x3]=nbc(3);
» func=x1'*x2+x3'/x1+x1*x2'*x3;
» btab(func,x1,x2,x3)

+-------------+----------+
| x1 x2 x3 | func(*) |
+-------------+----------+
| 0 0 0 | 1 |
| 1 0 0 | 0 |
| 0 1 0 | 1 |
| 1 1 0 | 0 |
| 0 0 1 | 0 |
| 1 0 1 | 1 |
| 0 1 1 | 1 |
| 1 1 1 | 1 |
+-------------+----------+

»

I know that there might be some strange stuff goin on with the order (little/big endian a.s.o.), which is one of the reasons I implemented the flip-functions.
Please mail me for suggestions of if you encounter any problems!

More toolboxes can be found at:

http://www.etek.chalmers.se/~e8rasmus/eng/matlab_programs.html

MATLAB release MATLAB 5.2 (R10)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
24 Jun 2003 deweir willie

how to work boolean algebra and demargins therem, it sames confusing.

08 Aug 2003 Rasmus Anthin

de Morgan's theorem is easy to test:

[a b]=nbc(2);
(a+b)'==a'*b'
(a*b)'==a'+b'

In both cases matlab will respond with bool object "1".

21 Apr 2006 Jon Dallimore

could perhaps stand a little bit of tidying up but otherwise VERY useful. Saved me about a weeks work on my dissertation by generating grey code for me.

02 Jan 2007 Shyang-Wen Tseng

It is very useful and saves me a few days to get the idea to program the same functions. Thank you.

Please login to add a comment or rating.
Updates
03 Dec 2002

I improved the toolbox a lot since the last "base" version. I have made a BOOL class with which you can do easy boolean arithmetics and other stuff.

Tag Activity for this File
Tag Applied By Date/Time
nbc Rasmus Anthin 22 Oct 2008 06:54:20
gray Rasmus Anthin 22 Oct 2008 06:54:20
truth table Rasmus Anthin 22 Oct 2008 06:54:20
boolean Rasmus Anthin 22 Oct 2008 06:54:20
bool class Rasmus Anthin 22 Oct 2008 06:54:20
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com