Quote:
Originally Posted by
daptal
To convert hex to decimal try using bc
Eg:- bc
ibase=16
3039
12345
and the second part of conversion of seconds to min 1 min = 60 sec so if $x sec is given $x/60 will give u min and so on
similarly for bytes use 1000 or 1024 as a standard
Thanks for your excellent solution.
Unfortunately neither my Linux embedded machine not Nokia Tablet come
with bc installable package.
So I have to look for another shell based only solution.
Great idea is to use in bc - input and out base (there is a number of good bc calculator examples I learned from Google).
For seconds conversion it would be nice to use timestamp, datetime
to read seconds as input and output result in one of available formats,
the same with bytes to Mbytes, Gbytes conversion,
as I need to write another conversion script for use in main script.
minutes = seconds (mod 60)
expr 5 % 3
2
works fine for constants
didn't work for seconds as variable
/="slash-equal" (divide variable by a constant)
%="mod-equal" (remainder of dividing variable by a constant)
It started to work for me as in the following example
# If you need a random int within a certain range, use the 'modulo' operator.
# This returns the remainder of a division operation.
RANGE=500
echo
number=$RANDOM
let "number %= $RANGE"
# ^^
echo "Random number less than $RANGE --- $number"
-
for remainder
seconds %= seconds
for minutes
minutes /= seconds
..
a=9
let "a %= 4"
echo $a
1
so a mod(4) = 1, exactly as 9 = 2*4 + 1 -
for conversion of seconds I would like to use epoch time
and date +%s
I get 95958
should be
The current
Unix epoch time is 1236954365
-
-
What is epoch time?
The
Unix epoch (or
Unix time or
POSIX time or
Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds. The epoch timestamp 0 can be written in ISO 8601 format as: 1970-01-01T00:00:00Z. One epoch hour is 3600 seconds, one epoch day is 86400 seconds long, leap seconds are not calculated. Many Unix systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).
Human readable time Seconds 1 minute60 seconds 1 hour3600 seconds 1 day86400 seconds 1 week604800 seconds 1 month (30.44 days) 2629743 seconds 1 year (365.24 days) 31556926 seconds
Jack