Hex conversion

# Thread: Hex conversion

1. Tim
Senior Member
Join Date
Dec 1969
Posts
552

## Hex conversion

I need to translate a 10 digit number to a HEX form, but when I try and do a <BR><BR>hex_number = hex(3246421756)<BR><BR>it should bring back C18076FC<BR><BR>However, I get a run time error - Overflow: &#039;[number: 3246421756]&#039; <BR><BR>If I do it with a 9 digit number it works fine, but I need the 10 ;-)<BR><BR>Any help would be gratefully received<BR><BR>Tim

2. Eddie Campbell Guest

## RE: Hex conversion

I&#039;m afraid that you are stuck. The maximum value you can pass to the Hex function is 2147483647 (i.e., the largest positive integer, using 32-bit arithmetic).<BR><BR>Sorry.

3. Tim
Senior Member
Join Date
Dec 1969
Posts
552

## RE: Hex conversion

**** it, <BR>Thanks for the Info, couldn&#039;t find it in MSDN, I&#039;ll have to work out a way around it.<BR><BR>Tim

4. Senior Member
Join Date
Dec 1969
Posts
614

## 32-bits is all you get..

A long integer is 32- bits (2147483647 largest +ve number)<BR><BR>BUT the HEX representation is a string - it does not matter how long it is (as far as you are concerned)<BR>so, if you split your number into 32 bit lumps you could worlk with it (you&#039;ll need to play about a bit) but here&#039;s a stab...<BR><BR> a=3246421756-2147483648 <BR> b=(3246421756-a)/2147483648 <BR><BR>alert hex(a ) &#039;returns 418076FC - binary 100 0001 1000 0000 0111 0110 1111 1100 (note last missing bit - due to signed maths)<BR>etc...<BR>alert hex(b ) &#039;Returns 1 - so this needs to be added to the left hand end of the first chunk so the 4 becomes C &#060;&#060;1100&#062;&#062;<BR><BR>Hope this helps<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
614

## BUT...

BUT the HEX representation is a string - it does not matter how long it is (as far as you are concerned) <BR>so, if you split your number into 32 bit lumps you could worlk with it (you&#039;ll need to play about a bit) but here&#039;s a stab... <BR>

6. Eddie Campbell Guest

## Nice thinking :) <eom>

.

7. Senior Member
Join Date
Dec 1969
Posts
614

## ta

.

8. Tim
Senior Member
Join Date
Dec 1969
Posts
552

## WOW

Thanks a lot, that gives me a huge hand. I was thinking of doing some arithmatic around the number itself first...but this way would actually work ;-)<BR>In case you wondering, I&#039;m trying to write something that would take the obscure URL addresses that are popping up all over the place and return the standard decimal ip address.<BR>ie 3246421756 is 193.128.118.252. Doing the reverse was the easy bit.<BR><BR>Tim<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•