# Create a list of binary numbers

echo {0..1}{0..1}{0..1}{0..1}
If you should happen to find yourself needing some binary numbers, this is a quickie way of doing it. If you need more digits, just add more "{0..1}" sequences for each digit you need. You can assign them to an array, too, and access them by their decimal equivalent for a quickie binary to decimal conversion (for larger values it's probably better to use another method). Note: this works in bash, ksh and zsh. For zsh, though, you'll need to issue a setopt KSH_ARRAYS to make the array zero-based. `binary=({0..1}{0..1}{0..1}{0..1})` `echo \${binary[9]}`
Sample Output
`0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111`

18
2009-06-23 17:30:20

## 1 Alternatives + Submit Alt

• Convert some decimal numbers to binary numbers. You could also build a general base-converter: `function convBase { echo "ibase=\$1; obase=\$2; \$3" | bc; }` then you could write `function decToBun { convBase 10 2 \$1; }` Show Sample Output

4
function decToBin { echo "ibase=10; obase=2; \$1" | bc; }
· 2009-11-24 22:57:58

### What Others Think

Although I can't think of a situation where this command would have helped me, it still gets a thumbs up for being cool :-) . Nice one.
Alanceil · 551 weeks and 3 days ago
Really surprised to see this command. I don't know of its use, but it rocks!
Bluehive · 551 weeks and 2 days ago
Wonderful -- I didn't know I could do things like {1..10}. That'll simplify some of my scripts.
tremby · 551 weeks and 2 days ago
@tremby: Yes, "for i in {1..10}; do", for example, comes in really handy. You can also do letters: "{m..p}" gives "m n o p".
dennisw · 551 weeks and 1 day ago
kewl!
kamathln · 540 weeks and 2 days ago

### What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

### What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.