I want to create a hex of the current number of nanoseconds since unix. (No need to be right, just accurate)
Here you can get the current nanoseconds in bash:
ksoviero@ksoviero-Latitude-E7440:~$ date +%s%N
1401993044859711108
Now, to turn it into hexadecimal, we use printf:
ksoviero@ksoviero-Latitude-E7440:~$ printf '%x\n' $(date +%s%N)
1374e157ee379028
See how easy it was?
Now try to do the same with Python. First, we get the current nanoseconds:
>>> from time import time
>>> print int(time() * 10**9)
1401993206893091840
Now we convert it to hex:
>>> print format(int(time() * 10**9), 'x')
1374e172f90a6400
I what!? Where did these two zeros come from at the end? They are always there, and they should not be ...
Ok, hold on, maybe Python hex functions can't handle large numbers. What happens if we just copy and paste nanoseconds?
>>> print format(1401993044859711108, 'x')
1374e13f086e6e84
Wait, it worked !?
- , ? , , ?