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

17
By: dennisw
2009-06-23 17:30:20

1 Alternatives + Submit Alt

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 · 490 weeks ago
Really surprised to see this command. I don't know of its use, but it rocks!
Bluehive · 489 weeks and 5 days ago
Wonderful -- I didn't know I could do things like {1..10}. That'll simplify some of my scripts.
tremby · 489 weeks and 5 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 · 489 weeks and 5 days ago
kewl!
kamathln · 478 weeks and 6 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.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: