How do I convert byte to int?

0 favourites
  • 7 posts
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • So, I've got a 8-byte string (32-bit integer value) which I need to convert into bit values and/or to an integer.

    More spesifically, I want to convert a 8 byte data I read from a file's header into it's numerical value.

    How can I do such conversions in C2?

  • Do you mean converting a binary number to a decimal number?

  • Do you mean the sort. Of thing you would use a strict for in c ? Unless JavaScript's runtime does this, you probably can't, it uses 64 bit floats

  • LittleStain Yeah, I mean kind of that.

    I have this ASCII data of "ü6‡ " (Little Endian) which is FC 36 87 00 in HEX (which I can't access in Construct2), and I want to convert it into it's Decimal equalivent of 8861436.

    Any way to do this in construct?

  • I'm not sure there is such a function/feature right away in C2, you might need to code your own.

    To be fair, this might even require you to make some third-part plugin using C2 SDK.

    Apparently JavaScript does have ways to do this conversion so making a plugin for it should work in the end.

    If you manage in getting directly the maths behind this conversion you can even try and implement your own Function in C2 possibly using system actions and expressions in the process (I'm not sure about the feasibility to be honest though).

  • There are a few expressions already:

    getbit(x, n)

    Get the nth bit of x represented as a 32-bit integer. For example getbit(7, 0) will get the least significant bit of the number 7 when represented as a 32-bit integer. Returns either 0 or 1.

    setbit(x, n, b)

    Set the nth bit of x represented as a 32-bit integer to b (either 0 or 1). The resulting 32-bit integer is returned.

    togglebit(x, n)

    Toggle the nth bit of x represented as a 32-bit integer. If that bit is 0, it is set to 1; if it is 1, it is set to 0. The resulting 32-bit integer is returned.

    And Yann made a plug:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Where is your data coming from? There is indeed a way to convert bytes to an integer but your string representation "ü6‡ " will definitely not equal to "FC 36 87 00" in JavaScript. "‡" charcode is 8225, and " " charcode is 32 (space). 8225 is more than a byte, and you probably meant the NULL character by your " ". It might be easier to receive your data in another form if you can.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)