How do I convert byte to int?

Get help using Construct 2

Post » Tue Jun 02, 2015 2:59 pm

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?
B
19
S
5
G
2
Posts: 23
Reputation: 1,729

Post » Tue Jun 02, 2015 3:05 pm

Do you mean converting a binary number to a decimal number?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jun 02, 2015 8:33 pm

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
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Wed Jun 03, 2015 6:22 am

@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?
B
19
S
5
G
2
Posts: 23
Reputation: 1,729

Post » Wed Jun 03, 2015 11:14 am

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).
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,317
Reputation: 87,483

Post » Wed Jun 03, 2015 11:20 am

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:
viewtopic.php?t=65827&start=0
Image ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

Post » Wed Jun 03, 2015 4:34 pm

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.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675


Return to How do I....?

Who is online

Users browsing this forum: Cubus32, tarek2 and 7 guests