Is there an equivalent to ASC() to get the numeric value of multiple bytes?

June 07th, 2012 - 08:02 am ET by NadCixelsyd | Report spam
I have a four byte string (e.g. 0x03020100) in little-endian format.
Is there a function that will convert this to a long (e.g. 66051).
I'm looking for something faster than ASC(MID$(STRING$,4)) * 16777216
+ ASC(MID$(STRING$,3)) * 65536 + ASC(MID$(STRING$,2)) * 256 +
ASC(STRING$)
email Follow the discussionReplies 15 repliesReplies Make a reply

Replies

#1 DaveO
June 07th, 2012 - 09:14 am ET | Report spam
"NadCixelsyd" wrote in message
news:
I have a four byte string (e.g. 0x03020100) in little-endian format.
Is there a function that will convert this to a long (e.g. 66051).
I'm looking for something faster than ASC(MID$(STRING$,4)) * 16777216
+ ASC(MID$(STRING$,3)) * 65536 + ASC(MID$(STRING$,2)) * 256 +
ASC(STRING$)



Not directly for littleendian like that if it was bigendian then no problem
just prefix a "&H" and away you go :

&H00010203 = 66051

You could try something like this: (untested air code)

"&H" & Right$(String,2) & Mid$(String,5,2) & Mid$(String,3,2) &
Left$(String,2)

Alternatively you may get better speed thus:

HexStr = "&H00000000"
Mid$(HexStr,3,2) = Right$(String,2)
Mid$(HexStr,5,2) = Mid$(String,5,2)
Mid$(HexStr,7,2) = Mid$(String,3,2)
Mid$(HextStr,9,2) = Keft$(String,2)

There may be a better way to transpose the bytes, perhap some API method I'm
blissfully unaware of.

DaveO.

Similar topics