Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hexa to decimal?? 1

Status
Not open for further replies.

RajVerma

Programmer
Jun 11, 2003
62
DE
hi all,

I wana convert an 8 digit hexa number to decimal. I found a very useful info at but unfortunately it supports only untill a certain limit of hexa numbers, for example it doesn't give correct values for higher than 7FFFFFFF but it works fine till 7FFFFFFF. but I want to convert even FFFFFFFF to decimal. how to extend this procedure to get the desired result?

thanx in adv,
Raj.
 
When I use "binary scan $h H8 d", where h is the (8-digit) hex string and d is the decimal string, it seems to work ok.

Bob Rashkin
rrashkin@csc.com
 
hi bob,
thanx for the reply. I'm still not getting the result even after trying the way u suggested. it is giving the following results.

(Raj) 95 % binary scan FFFFFFFF H8 d
1
(Raj) 96 % set d
46464646

how do I get the decimal equivalent of FFFFFFFF, which is 4294967295?

thanx,
Raj.
 
Sorry, I was wrong about that. This seems to work better:

set h 0xffffffff
set d [format %u $h]


d = 294967295

Bob Rashkin
rrashkin@csc.com
 
thanx bob,

I also want to convert the same hexa number into a binary equivalent. I tried different ways but cudn't succeed. can anyone let me know how to do it.

thanx,
Raj.
 
Do you mean a real binary number (i.e., 8 hex characters = 4 bytes -> 32 bit binary) or an ASCII representation of 32 binary bits?

Bob Rashkin
rrashkin@csc.com
 
hi bob,

if my hex is 'FFFFFFFF', then I want to get the binary equivalent to be '11111111111111111111111111111111', b'cos different bits mean different things in this set of 32 bits.

thanx,
Raj.
 
set h 0xffffffff
set d [format %u $h]
binary scan [binary format I $d] B32 b


There's probably more elegant and/or direct ways of doing it. This is my way.



Bob Rashkin
rrashkin@csc.com
 
These are areas I am weak in.
Thanks for the topic and the answers!
 
hi bob,

still I'm not getting the desired output, it just gives '1' as output for wat ever hexa number I give!!

thnx,
Raj.
 
The "1" means it made 1 conversion ("it" being "binary scan"). In my example, the new variable is "b".

Bob Rashkin
rrashkin@csc.com
 
oh my goodness, I didn't try what b meant in the previous go. thanx bob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top