Bitwise operations

Discussion and feedback on Construct 2

Post » Sun Apr 23, 2017 7:59 am

How is -1 (or any negative number) represented as a binary number in construct?

For the purposes of using setbit on unassigned tiles in a tilemap.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Sun Apr 23, 2017 2:29 pm

This is generally how the bits are for negative integer numbers.
https://en.m.wikipedia.org/wiki/Two%27s_complement
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762

Post » Sun Apr 23, 2017 5:49 pm

Interesting, thanks! So -1 actually is supposed to be all 1s. I thought getbit wasn't working correctly with a negative number or something ><

I guess that means the last bit is reserved for determining a negative number or not, so an 8 bit number would range from -128 to 127 rather than 0 to 255.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Sun Apr 23, 2017 6:02 pm

Correct. Also keep in mind that typically numbers in javascript (or construct) are 64bit floating point numbers, but whenever a bitwise operation in done on them they are cast to a 32bit integer. So the number range is −2,147,483,648 to 2,147,483,647
B
91
S
31
G
103
Posts: 5,238
Reputation: 67,762


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests