Convert Binary-Integer in String to real Integer

  1. 6 days ago

    Hello everyone,

    how to convert a data type packed in a string back to its original type?

    For example
    The first 8 bytes of a string contain a UInt32 number:
    B90D 0000 0000 0000 [Binary]

    How can I make 3513 [Dec] out of it?

    Here's what I tried to do:

    Dim mbc As MemoryBlock = StringRepresentationOfInteger
    Dim mb As New Xojo.Core.MutableMemoryBlock( mbc, mbc.Size )
    Dim tmp As UInt32
    tmp = mb.UInt32Value(0)

    It works, but is that the best way?

    That looks more like an int64 to me (since every hex digit is 4 bits)
    other than that endianess _may_ be relevant but this is a reasonable way to do this

  2. Norman P

    Nov 13 Xojo Inc Answer

    That looks more like an int64 to me (since every hex digit is 4 bits)
    other than that endianess _may_ be relevant but this is a reasonable way to do this

  3. Christian S

    Nov 13 Pre-Release Testers, Xojo Pro Germany

    the conversion from old memory block to new memory block is an extra unnecessary step.

  4. Edited 6 days ago

    @Norman P That looks more like an int64 to me (since every hex digit is 4 bits)
    other than that endianess _may_ be relevant but this is a reasonable way to do this

    Your're right. It's UInt64, my fault.

    @ChristianSchmitz the conversion from old memory block to new memory block is an extra unnecessary step.

    You're right. This works too:

    Dim mbc As MemoryBlock = StringRepresentationOfInteger
    Dim tmp As UInt64
    tmp = mbc.UInt64Value(0)

or Sign Up to reply!