473,795 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Has anyone posted code to convert longer HEX numbers to DEC strings?

MLH
The largest integer A97 can deal with is 2,147,483,647,
as I understand it from HELP. I would be content to represent
larger integers as strings. For example, "2147483648 " would
suit me fine. I would be interested in converting larger HEX
numbers to decimal integer equivalents. For example, a 16-digit
HEX number is quite a large decimal value and I would be
happy to represent it as a string, as it would suit my purposes
fine. Since the math, however, is not going to be calculated
by Access, it seems an intimidating task to code it. Was wondering,
perhaps, if someone might have already done so.
Dec 2 '05
28 4820
"kaniest" <ka*****@xs4all .nl> wrote in
news:43******** *************** @news.xs4all.nl :
David W. Fenton <dX********@bwa y.net.invalid> wrote:
MLH <CR**@NorthStat e.net> wrote in
news:qv******** *************** *********@4ax.c om:
On 1 Dec 2005 16:30:06 -0800, "Lyle Fairfield"
<ly***********@ aim.com> wrote:
I also believe that somewhere, somehow, sometime, variant
decimals were changed, allowing larger numbers. And I believe
that the VBA variant decimal type is not identical with JET's
decimal data type which permits maximium values of only 10^28 - 1.

Well that is great news!
281474976710655 Variant Decimal
56294995342131 Above Amount Div by 5
16777216 Square Root of the First Number
Now, if I can come up with an ingenious way to break
down Variant Decimal values larger than &hFFFFFFFF,
I'll be home free. I'll bet someone clever has already
figured out and posted a way to convert numbers up
to 281474976710655 to HEX strings.
???

Lyle's code operates on #hFFFFFFFFFFFF, which is the number
you're looking for.

I don't know what Lyle is talking about with his decimal

veriant.
Why not upto #hFFFFFFFFFFFFF FFFFFFFFFFF
=7922816251426 433759354395033 5, the largest variant decimal?


Because MLH asked about a range up to #hFFFFFFFFFFFF in his
original
post.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Dec 3 '05 #11
David W. Fenton <dX********@bwa y.net.invalid> wrote:
"kaniest" <ka*****@xs4all .nl> wrote in
news:43******** *************** @news.xs4all.nl :
David W. Fenton <dX********@bwa y.net.invalid> wrote:
Lyle's code operates on #hFFFFFFFFFFFF, which is the number
you're looking for.

I don't know what Lyle is talking about with his decimal veriant.


Why not upto #hFFFFFFFFFFFFF FFFFFFFFFFF
=79228162514264 337593543950335 , the largest variant decimal?


Because MLH asked about a range up to #hFFFFFFFFFFFF in his
original
post.


That's only 12 hex digits, he asked for 16.
This returns a variant decimal from a string with upto 24 hex digits:

function f(x$):f=cdec(0)
dim i&:for i=1 to len(x)
f=16*f+("&h" & mid$(x,i,1))
next i
end function

--
Paul
Dec 3 '05 #12
It's a nice function.
How about the other way, ie return a variant decimal from a hex string
of up to 24 hex digits?

Dec 3 '05 #13
Of course I mean the other way:
hex string of up to 24 characters from a variant decimal.

Dec 3 '05 #14
Lyle Fairfield <ly***********@ aim.com> wrote:
Of course I mean the other way:
hex string of up to 24 characters from a variant decimal.


function g$(x)
dim x0,x1
x0=int(abs(cdec (x)))
do while x0>0
x1=int(x0/16)
g=hex(x0-16*x1) & g
x0=x1
loop
if g="" then g="0"
end function

--
Paul
Dec 3 '05 #15
kaniest wrote:
Lyle Fairfield <ly***********@ aim.com> wrote:
Of course I mean the other way:
hex string of up to 24 characters from a variant decimal.


function g$(x)
dim x0,x1
x0=int(abs(cdec (x)))
do while x0>0
x1=int(x0/16)
g=hex(x0-16*x1) & g
x0=x1
loop
if g="" then g="0"
end function


Your functions are great and, I suspect they always return the right
answer, (I'm not so sure about that for mine!)
But I'm posting mine here not so much to suggest them as an alternative
but as a comment on the disparate ways humans can think!

Option Explicit

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMem ory" _
(Destination As Any, Source As Any, ByVal Length As Long)

Public Function VariantDecimalA sHexString(ByVa l VariantDecimal As
Variant) As String
Dim z(3) As Long
CopyMemory z(0), ByVal VarPtr(VariantD ecimal) + 4, 4
CopyMemory z(1), ByVal VarPtr(VariantD ecimal) + 8, 4
CopyMemory z(2), ByVal VarPtr(VariantD ecimal) + 12, 4
If z(0) <> 0 Then _
VariantDecimalA sHexString = _
VariantDecimalA sHexString & Hex(z(0))
If z(2) <> 0 Then _
VariantDecimalA sHexString = _
VariantDecimalA sHexString & Hex(z(2))
If z(1) <> 0 Then _
VariantDecimalA sHexString = _
VariantDecimalA sHexString & Hex(z(1))
If Len(VariantDeci malAsHexString) = 0 Then
VariantDecimalA sHexString = "0"
End Function

Public Function HexStringAsVari antDecimal(ByVa l HexString As String) As
Variant
HexStringAsVari antDecimal = CDec("0")
HexString = Right(String(24 , "0") & HexString, 24)
Dim z(3) As Long
z(0) = "&h" & Mid$(HexString, 17, 8)
z(1) = "&h" & Mid$(HexString, 9, 8)
z(2) = "&h" & Mid$(HexString, 1, 8)
CopyMemory ByVal VarPtr(HexStrin gAsVariantDecim al) + 8, z(0), 4
CopyMemory ByVal VarPtr(HexStrin gAsVariantDecim al) + 12, z(1), 4
CopyMemory ByVal VarPtr(HexStrin gAsVariantDecim al) + 4, z(2), 4
End Function

Dec 4 '05 #16
Lyle Fairfield wrote:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMem ory" _


.... may save quite a few cycles. I could change f() to:

function f(x$):f=cdec(0)
dim x0$:x0=string(2 4-len(x),"0") & x
copymemory byval varptr(f)+4,cln g("&h" & mid$(x0,1,8)),4
copymemory byval varptr(f)+12,cl ng("&h" & mid$(x0,9,8)),4
copymemory byval varptr(f)+8,cln g("&h" & mid$(x0,17,8)), 4
end function

The other way round is complicated by Hex() dropping leading
zeroes, well ... mmm ... zzz ...

BTW, what happend to the infamous 12 hex digit upper limit?

--
Paul
Dec 4 '05 #17
kaniest wrote:
BTW, what happend to the infamous 12 hex digit upper limit?


Is it 12 digits or 12 bytes?

--
Lyle Fairfield
Dec 4 '05 #18
Lyle Fairfield wrote:
kaniest wrote:
BTW, what happend to the infamous 12 hex digit upper limit?


Is it 12 digits or 12 bytes?


#hFFFFFFFFFFFF, according to David. That hints at 12 hex digits, or?
Dec 4 '05 #19
kaniest wrote:
Lyle Fairfield wrote:
kaniest wrote:
BTW, what happend to the infamous 12 hex digit upper limit?

Is it 12 digits or 12 bytes?


#hFFFFFFFFFFFF, according to David. That hints at 12 hex digits, or?


The length of a variant decimal is, like all variants, 16 bytes.

The first two bytes indicate the subtype of the variant, in this case,
14 -> decimal.
The third byte is the number of decimal places.
The fourth byte is zero for positive, 128 for negative. TTBOMK the other
bits of this byte are not used to add to the value of the decimal as
they might be in a twos complement kind of representation. Decimals are
not a twos complement kind of representation which is why
FFFFFFFFFFFFFFF FFFFFFFFF is not -1 but 792281625142643 37593543950335.

The last twelve bytes are the value of the decimal, but in what is to me
a rather strange configuration. As nearly as I can tell the order of
the bytes is 1,2,3,4,9,10,11 ,12,5,6,7,8 if we thought about them in the
order we consider normal for decimal; I was prepared for byte 1 (of the
12) or byte 12 being 1 to 255, but not byte 8. Perhaps someone can shed
some light on this.

One can slam dunk 12 bytes of ff (with copymemory) and one gets a
working decimal. I think you previously posted the size:
792281625142643 37593543950335
If one stores
792281625142643 37593543.950335
or
-792281625142643 37593543.950335
the 12 value bytes don't change at all; the third byte becomes 6 and the
4th byte becomes 128 (for the negative).

Perhaps, there is some validity to a limit of 12 hex digits for some
other data type (although I can't think of what it could be unless
perhaps doubles are limited to 6 bytes for integer part). I think there
is no such limit for the variant decimal.

--
Lyle Fairfield
Dec 4 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
1701
by: Ian Richardson | last post by:
I'm writing a large Javascript application (uncompressed source around 400K) which is doing almost all the initialisation it needs to in a just-in-time manner. However, I have included an option for almost all of this to be done when the application first starts. Under this circumstance, and since the last few nightly builds of Mozilla, I've been getting: Script warning:
4
1384
by: Milan Cermak | last post by:
Hi all, I'm developing my own basic classes library (http://stlib.sf.net for those how are interested) and I'd like to compare its power to STL. Unfortunately I'm not familiar with STL - it blows up my mind everytime I try to understand it. Could you, please, show me the code implementing following functionality? Consider two strings that contains only digits. These strings are 7 to 15 digits long. (They are telephone numbers read...
7
41374
by: Philipp H. Mohr | last post by:
Hello, I am trying to xor the byte representation of every char in a string with its predecessor. But I don't know how to convert a char into its byte representation. This is to calculate the nmea checksum for gps data. e.g. everything between $ and * needs to be xor: $GPGSV,3,1,10,06,79,187,39,30,59,098,40,25,51,287,00,05,25,103,44* to get the checksum.
6
6161
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but my mappings between named colors, HEX values and the Long Integer values used in Access are not jibbing. Anyone have a nice list laying around? Danny J Lesandrini dlesandrini@hotmail.com
17
2094
by: Sean Kenwrick | last post by:
I am writing a byte-code interpreter/emulator for a language that exclusively uses strings for variables (i.e all variables are pushed onto the stack as strings). Therefore for arithmetic operations I need to convert the string to a 32 bit integer, carry out the arithmetic operation, then convert it back to a string before pushing it back onto the stack. This can happen millions of times per second so it is essential that I have...
11
4845
tpgames
by: tpgames | last post by:
I've struck zero in finding a Link to a sudoku game that actually uses images for numbers, even images OF numbers. Yes, I'd prefer the game in JavaScript. Every site I've been too, (hundreds) uses CSS and HTML and NOT images. I've only found 1 site that uses images, and their source code is NOT available for viewing, at all. I can't even find that site anymore. I do mean that the game itself uses images in solving the problem. I do not mean,...
29
5090
by: Harlin Seritt | last post by:
Hi... I would like to take a string like 'supercalifragilisticexpialidocius' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in something like ascii text editor. I'd also like to be able to read the binary formed data back into string format so that it shows the original value. Is there any way to do this in Python? Thanks!
15
2369
by: Steve | last post by:
I am having problems getting values out of an array. The array is set as a global array and values are pushed into it as they are read from a JSON file using a "for loop". When the "for loop" is finished I want to convert the array into a string which can be used by another function. My attempt to do this is not working. The script looks like this: heights=; function getElevationInter(latv,lngv) { var script =...
12
2262
by: Fett | last post by:
I need a crypto package that works on windows with python 2.5. Can anyone suggest one for me? I have been searching for a couple days for a good cryptography package to use for public/private key encryption, at this point I would settle for symmetric even. Every encryption package I have found for python was either operating system specific (read *nix only): http://www.freenet.org.nz/ezPyCrypto/
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.