News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Byte array to Int

Started by Jackal, April 13, 2010, 05:19:22 PM

Previous topic - Next topic

Jackal

I was wondering how do I convert a byte array to an integer.

for instance 00 00 2B 6F     = 16,375

redskull

The easiest way is BSWAP.  However, there are all sorts of various ways using logic, rotating, shifting, and multiplying, and you will more than likely get 100 different responses as the members fight to the death over which is fastest.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Ghandi

Quote
and you will more than likely get 100 different responses as the members fight to the death over which is fastest.

rofl :D

HR,
Ghandi

dedndave

actually, speed for that is only critical if you have to convert thousands of values
usually, these routines are used a few times - go for something small and convenient to use
you can use some of the C lib functions if you want

Slugsnack

Quote from: Jackal on April 13, 2010, 05:19:22 PM
I was wondering how do I convert a byte array to an integer.

for instance 00 00 2B 6F     = 16,375
i maybe missing something but how is that even a conversion. i'd have thought it might convert to 11119 or 1865089024. where did 16375 come from :|

dedndave

...or 0,0,43,111
he did say it was a byte array   :bg
but, you're right, Mike
the answer he probably wants is 1865089024

Jackal

Quote from: dedndave on April 13, 2010, 09:03:23 PM
...or 0,0,43,111
he did say it was a byte array   :bg
but, you're right, Mike
the answer he probably wants is 1865089024



That answer is wrong. The answer was wrong in my first post also. I got it i think. Its Big Endian and Int32 so my asnwer I needed to get was 11,119.

qWord

Quote from: Jackal on April 13, 2010, 10:07:33 PMIts Big Endian and Int32 so my asnwer I needed to get was 11,119.
load the value into an register and use bswap r32 to convert it from network byte order to littel endian. Then yo can use the sdword$(r32/mem32)-macro to convert it to an string (or use directly crt_sprintf-function)
mov eax,SDWORD ptr ...
bswap eax
invoke MessageBoxA,0,sdword$(eax),0,0
FPU in a trice: SmplMath
It's that simple!

jj2007

Quote from: qWord on April 13, 2010, 10:20:31 PM
bswap eax,eax

That is a cute addition to the x86 instruction set, thanks. I hope bswap eax, [ebx] works, too :green

qWord

Quote from: jj2007 on April 13, 2010, 10:57:06 PM
That is a cute addition to the x86 instruction set, thanks. I hope bswap eax, [ebx] works, too :green
:bg
FPU in a trice: SmplMath
It's that simple!

Jackal

all taken care of. Thanks.