how to write Binary table in simple way ?
Show older comments
Hi there,
1. How to create Binary code (like this one below) in a simple way?
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
2. how to print only the relevant rows like:
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
only the rows that has 2 bits that equal to 1.....
Thanks,
Henry
Accepted Answer
More Answers (1)
Pierre Bulens
on 28 Jul 2019
0 votes
dec2bin function gives the table :

to get the rows containing 2 bits equal to 1, use the sum function and logical indexing

the sum function gives the number of 1s in each row,
the '== 2' part selects the wanted rows
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!