Check if it's your binary birthday!

echo "obase=2;$((($(date +%s)-$(date +%s -d YYYY-MM-DD))/86400))" | bc
Print out your age in days in binary. Today's my binary birthday, I'm 2^14 days old :-) . This command does bash arithmatic $(( )) on two dates: Today: $(date +%s) Date of birth: $(date +%s -d YYYY-MM-DD) The dates are expressed as the number of seconds since the Unix epoch (Jan 1970), so we devide the difference by 86400 (seconds per day). . Finally we pipe "obase=2; DAYS-OLD" into bc to convert to binary. (obase == output base)
Sample Output
$ echo "obase=2;$((($(date +%s)-$(date +%s -d 1970-12-10))/86400))" | bc
100000000000000

2
By: flatcap
2015-10-19 15:40:32

These Might Interest You

  • The options -b binary and -m are needed for disassembling raw machine code when it is not part of a full binary executable with proper headers. Show Sample Output


    2
    objdump -b binary -m i386 -D shellcode.bin
    recursiverse · 2010-04-27 11:11:36 2
  • bvi is your vi for binary editing. If your system does not have it, you can get it from http://bvi.sourceforge.net/


    -3
    bvi [binary-file]
    haivu · 2009-03-24 15:30:50 0
  • 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]} Show Sample Output


    17
    echo {0..1}{0..1}{0..1}{0..1}
    dennisw · 2009-06-23 17:30:20 5
  • Please note that binary file checking is NOT perfect. So, use it with caution. It does not delete hidden files whose name has a leading '.' character. And it regards an empty file as a binary file.


    1
    perl -e 'unlink grep { -f -B } <*>'
    seungwon · 2011-04-05 10:32:40 0

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: