Xojo Conferences
MBSOct2019CologneDE

Re: Little-endian 32-bit number as string (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: [ANN] Writer 2.7 Released!
Next thread: Change ProcID at runtime


Re: Little-endian 32-bit number as string   -   Adam Ernst
  Re: Little-endian 32-bit number as string   -   Noah Desch
  Re: Little-endian 32-bit number as string   -   Charles Yeomans

Re: Little-endian 32-bit number as string
Date: 08.05.02 21:40 (Wed, 8 May 2002 15:40:31 -0500)
From: Adam Ernst
If I have a four-character (32-bit) number stored as a string, how do I
convert it to an integer (or double, if the range or an integer is too
small). The number is in little-endian as well, complicating things a
bit.

Any help would be much appreciated.

Thanks,

Adam

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Little-endian 32-bit number as string
Date: 08.05.02 21:56 (Wed, 8 May 2002 16:56:32 -0400)
From: Noah Desch

On Wednesday, May 8, 2002, at 04:40 PM, Adam Ernst wrote:

> If I have a four-character (32-bit) number stored as a string, how do I
> convert it to an integer (or double, if the range or an integer is too
> small). The number is in little-endian as well, complicating things a
> bit.

Dim M As Memoryblock
M = NewMemoryblock(4)

M.StringValue(3,1) = Midb( TheString, 1, 1 )
M.StringValue(2,1) = Midb( TheString, 2, 1 )
M.StringValue(1,1) = Midb( TheString, 3, 1 )
M.StringValue(0,1) = Midb( TheString, 4, 1 )

return M.Long(0)

You might want to check out the 4.5 alphas since they've added a
"LittleEndian" property to the memoryblock which makes the byte swapping
above unnecessary.

-Noah Desch
Wireframe Software
http://wireframe.virtualave.net

Icon Brush - the fast and easy icon creator

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Little-endian 32-bit number as string
Date: 08.05.02 22:09 (Wed, 8 May 2002 17:09:53 -0400)
From: Charles Yeomans
Use a MemoryBlock; you will need to handle endianness yourself. Below
is some code that I've not tested.

Charles Yeomans

Function ConvertStringToInteger(s as String, isLittleEndian as Boolean)
as Integer
dim m as MemoryBlock
dim tempByte as Integer

m = NewMemoryBlock(4)
m.StringValue(0,4) = Left(s, 4)
If IsLittleEndian then //swap bytes
tempByte = m.byte(0)
m.byte(3) = m.byte(0)
tempByte = m.byte(1)
m.byte(1) = m.byte(2)
m.byte(2) =tempByte
End if
Return m.long
End Function



On Wednesday, May 8, 2002, at 04:40 PM, Adam Ernst wrote:

> If I have a four-character (32-bit) number stored as a string, how do I
> convert it to an integer (or double, if the range or an integer is too
> small). The number is in little-endian as well, complicating things a
> bit.
>
> Any help would be much appreciated.
>
> Thanks,
>
> Adam
>
> ---
> Subscribe to the digest: <mailto:realbasic-nug-
> <email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>


---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>