How to convert hex numbers to decimal ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to convert hex numbers to decimal ?
# 8  
Old 03-13-2009
Quote:
Originally Posted by jack2
Hi,

just tested code from reply in this thread.
-
-

$ TIME=$( date +%s )
$ LANG=C date -ud @`echo $TIME`
Fri Mar 13 14:37:15 UTC 2009

-
Jack
ok, thanks for sharing. Is there a question here?
# 9  
Old 03-13-2009
Quote:
Originally Posted by vgersh99
what's "%s" - it's valid options under Solaris? What OS are you under? What's it supposed to return?
what's 'dat'?
Why are you doing this: '@`echo $time`'? What '@' for? Why do you need 'echo'?
'%s' - Output seconds since the epoch (works at least for Linux and HP-UX 11.31)
date -d @time shows the formatted time for this UNIX timestamp, dunno why it needs that @, but it does. I put in in there for demonstration purpose only, to show the calculation works.
# 10  
Old 03-13-2009
Quote:
Originally Posted by pludi
'%s' - Output seconds since the epoch (works at least for Linux and HP-UX 11.31)
date -d @time shows the formatted time for this UNIX timestamp, dunno why it needs that @, but it does. I put in in there for demonstration purpose only, to show the calculation works.
ah, ok - thanks - I don't have that under Solaris.
# 11  
Old 03-13-2009
Quote:
Originally Posted by pludi
'%s' - Output seconds since the epoch (works at least for Linux and HP-UX 11.31)
date -d @time shows the formatted time for this UNIX timestamp, dunno why it needs that @, but it does. I put in in there for demonstration purpose only, to show the calculation works.

unfortunately, on my Linux Tablet (embedded TI Debian)
date -ud @`echo $time`
generates
date: invalid date '@118573'

Ok.
The most important thing is to convert hex seconds to decimal seconds,
than to minutes, hours on my Linux Tablet.

thanks,

Jack
# 12  
Old 03-13-2009
Two things that come to mind:
  1. Check your time on the tablet, maybe it isn't set correctly
  2. Check the output of date --help, maybe %s doesn't print the epoch-time in your version
Because a six digit epoch time sure as hell isn't right (except if you're posting through time. In that case I might have some messages for you to relay to Mr. Thompson, Mr. Kernighan, Mr. Ritchie, and some others...)
# 13  
Old 03-13-2009
Quote:
Originally Posted by pludi
Two things that come to mind:
  1. Check your time on the tablet, maybe it isn't set correctly
  2. Check the output of date --help, maybe %s doesn't print the epoch-time in your version
Because a six digit epoch time sure as hell isn't right (except if you're posting through time. In that case I might have some messages for you to relay to Mr. Thompson, Mr. Kernighan, Mr. Ritchie, and some others...)
You are completely right.
Epoch time on my old Internet Tablet is
Fri Jan 2 11:00:50 CET 1970
I loaded acu, get it wifi connected to the Internet
and expected time to reset.
Unfortunately. Nothing of this kind.

Ok. All I need is to convert sex seconds into decimal seconds
than into readable format like

01:44:46
and convert hex bytes into decimal bytes, than into something like

4.481MB or 1.026GB

I need to timestamp converted data with a real date.

Read how to configure my tablet to get connected to ntp server on boot up but don't know if it supports the described procedure.

Set time manually.
Run example and the same error, as system time has nothing to do with the problem (I suppose so).

I need to count seconds and convert into minutes, hours, days,
so I go to test example from reply.

thanks
Jack
# 14  
Old 04-06-2009
The bash shell has built-in conversions to handle octal and hex numbers, consider the following:

svn1:~# (( x = 0377 )); echo $x
255

This example will set X to an octal value of 0377, which is 255 in decimal.

svn1:~# (( x = 0xFFFE )); echo $x
65534

This example will set x to a hex value of 0xFFFE, which is 65534.

The use of (( and )) is a shorthand for the "let" statement.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Urgent help needed.. C++ program to convert decimal to hexa decimal

Hi , seq can be 0...128 int windex = seq / 8; int bindex = seq % 8; unsigned char bitvalue = '\x01' << (7-bindex) ; bpv.bitmapvalue = bitvalue; This is the part of a program to convert decimal to bitmap value of hexadecimal. I want this to change to convert only to... (1 Reply)
Discussion started by: greenworld123
1 Replies

2. Shell Programming and Scripting

Converting decimal to hex

How to convert decimal value to hex and than take 1st digits as variable sample data 84844294,5,6 51291736,2,3 84844294,5,6 51291736,2,3 i can use {printf "%x,%d\n",$1,$2} but than i want to filter base on 1st hex digit 1st recrd (1 Reply)
Discussion started by: before4
1 Replies

3. Shell Programming and Scripting

How to convert a file containing hex code to decimal using script?

The file contains code like the below and need to convert each one into a decimal 00 00 00 04 17 03 06 01 So the output should come as 0 0 0 4 23 3 6 1 (24 Replies)
Discussion started by: necro98
24 Replies

4. Shell Programming and Scripting

Convert hex to decimal

can someone help me in converting hex streams to decimal values using perl script Hex value: $my_hex_stream="0c07ac14001676"; Every hex value in the above stream should be converted in to decimal and separated by comma. The output should be: 12,07,172,20,00,22,118 (2 Replies)
Discussion started by: Arun_Linux
2 Replies

5. UNIX for Advanced & Expert Users

Convert 32 bit hex value into fields in decimal

I have 32 bit value in hex that I want to separate into fields and then convert the fields into decimal values. Input file has 2 words of 32 bit hex values: 000001ac ca85210e Output both words separated into individual bit fields: ca85210e: f1(31:9), f2(8:0) f7c392ac: f1(31:14),... (2 Replies)
Discussion started by: morrbie
2 Replies

6. Shell Programming and Scripting

Decimal to hex conversion

Dear All PROs Thanks in advance need a shell for Decimal to hex conversion input file (decimal values) 65,5,48,66,133,131,118,47 65,5,48,66,133,131,83,63 . . desire output should be (Hex value)... (11 Replies)
Discussion started by: The_Archer
11 Replies

7. Shell Programming and Scripting

Convert hex to decimal or reverse is better?

Please Help Me! about the problem down under. I have 2 files with nearly the same characteristics, I have to convert one to the other format or the other format to one's format. I want to write it with awk. The first file contain lines like this: 300000001#A#Y#Y#Y#Y The other file contain... (4 Replies)
Discussion started by: Axel82
4 Replies

8. Shell Programming and Scripting

hex to decimal

hi all, echo "ibase=16;obase=10;11" | bc shouldn't i get 17? i am getting 11 i am trying to convert 11 (hex) to decimal stuck! JAK (4 Replies)
Discussion started by: jakSun8
4 Replies

9. Shell Programming and Scripting

Hex to Decimal Convertion

Dear all, I have a file like this. EE48 4473 7FC9 EE48 102C D23 EE48 4DD 27D EE48 0 0 EE48 3FFE 854 F230 DC6 ... (1 Reply)
Discussion started by: Nayanajith
1 Replies

10. UNIX for Advanced & Expert Users

Req on how to convert hex numbers to decimals

Hi, If i have an input as c1:41 c2:0x0000.00046b3e I want to make output display as c1:41 c2:224062 . Basically convert first part 0x0000 (as hex) to decimal which is 0 and convert second part 0x00046b3e (as hex) to decimal which is 289598 and as such add both parts namely... (3 Replies)
Discussion started by: hare
3 Replies
Login or Register to Ask a Question