| View previous topic :: View next topic |
| Author |
Message |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Feb 07, 2002 11:42 am Post subject: @HEX() function |
|
|
I use the @HEX() function to format some values. My problem is that if the resulting hex number has one or more leading zeros, @HEX() will remove them automatically (i.e. 01234 will be 1234).
Normally that would not be an issue, but in this case I really to keep leading zeros. Anyone has an idea how to do this?
Thanks.
Dr. Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Feb 07, 2002 7:46 pm Post subject: |
|
|
How about a loop to check for leading zeroes before
the @hex() function, save them, and append the
@hex() result to the zeroes?
Something like this maybe:
__________________________________________________________________________________________________________________________
| Code: |
%n = 0012345
%s = ""
%x = 1
REPEAT
if @equal(@substr(%n, %x), 0)
%s = %s@substr(%n, %x)
end
%x = @succ(%x)
UNTIL @not(@equal(@substr(%n, %x),0))
%n = %s@hex(%n)
INFO test %n
|
_________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Fri Feb 08, 2002 7:42 am Post subject: |
|
|
Hi again, Mac!
Thanks for the suggestion. But I don't think that it will work because input values do not necessarily have any leading 0's - they appear in hex output, or rather they don't because the @hex() function removes them.
Let me give you an example:
| Code: | %i = 121843147
%o = @hex(%I)
info Input (%i) = Output (%o) |
So output is 7432DCB, but it should have been 07432DCB
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Fri Feb 08, 2002 12:29 pm Post subject: |
|
|
The following may be what you want:
| Code: |
%i = 121843147
%o = @hex(%I,8)
info Input (%i) = Output (%o)
|
Tommy |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Fri Feb 08, 2002 1:52 pm Post subject: |
|
|
I had tried that one (defining length of @hex() output) already. It works fine, but only when working with fixed-length values. Problem is that my input (and therefore output) has varying length.
But hey, it gives me an idea now. There just might be a way for me to determine the expected length of each @hex() output - if that's possible I can follow your suggestion..
%i = 121843147
%%length = "expected length"
%o = @hex(%I,%%length)
I will try to rewrite my routines and see if this puppy will run! Thanks
Dread  _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
|