1

I recently came across information that on the 15th of May at 02:09:25 Unix time will be equal to 1010101010101010101010101010101 in binary representation.

I wanted to find out whether it is a fake or not, so I was trying to get the current Unix time in binary. I came up with a simple prompt like this:

$ date +%s | xxd -b

And I got a result like this:

0000000: 00110001 00110100 00110011 00110001 00110100 00110110  143146
0000006: 00110010 00110100 00110100 00110010 00001010           2442.

All in all, I got:

0011000100110100001100110011000100110100001101100011001000110100001101000011001000001010

But it shows much more digits than I expected. All the other variations were unsatisfactory as well such as $ date "+%v %H:%M:%S" | xxd -b or $ date | xxd -b.

I guess, this pair of date and xxd commands is not going to give me the expected result.

Could you tell me how can I get the current time in such a binary representation that I will get 1010101010101010101010101010101 on the 15th of May at 02:09:25?


Update:

OK, so using this online converter (http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html) I was able to get a reasonable number of digits. How can I achieve the same using bash?

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
  • 3
    Note that `date '+%s'` generated a string of decimal digits encoded in ASCII, and the `xxd -b` converted the ASCII character for each digit into binary (the `0011` followed by 4 bits is 48 + digit). – Jonathan Leffler May 12 '15 at 20:58
  • 1
    That's 0x55555555 in hexadecimal. And it means that, as of Fri 2015-05-15 02:09:25 UTC, we've used up 2/3 of the range of times from the epoch to 2*31-1 seconds, when 32-bit signed `time_t` overflows. – Keith Thompson May 12 '15 at 21:12

1 Answers1

7

Try this:

echo "obase=2;$(date +%s)" |bc
Jahid
  • 21,542
  • 10
  • 90
  • 108