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
52
S
26
G
110
Posts: 1,623
Reputation: 62,167

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
92
S
32
G
110
Posts: 5,295
Reputation: 71,501

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
52
S
26
G
110
Posts: 1,623
Reputation: 62,167

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
92
S
32
G
110
Posts: 5,295
Reputation: 71,501


Return to Construct 2 General

Who is online

Users browsing this forum: dand, whitephon and 14 guests