# Bitwise operations

Discussion and feedback on Construct 2

### » 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.
B
60
S
30
G
134
Posts: 1,949
Reputation: 75,375

### » 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
100
S
38
G
134
Posts: 5,556
Reputation: 85,325

### » 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.
B
60
S
30
G
134
Posts: 1,949
Reputation: 75,375

### » 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
100
S
38
G
134
Posts: 5,556
Reputation: 85,325