I declared a variable mask of int type, then do some and mask updated by mask &g


#1

i declared a variable mask of int type, then do some and mask updated by mask >>= 1 , and i got BUS error(I don’t know what the hell is this) on my code then i changed mask /= 2 and code got AC o.O . can anyone suggest why this is happned?


#2

The minions are actively looking into your issue. Just sit back and relax. They will get back to you.


#3

Anshuman Singh ok :slight_smile: and thnx :wink:


#4

Paras Meena Hm, so this is interesting. The int mask = (1<<31) is not a positive number. Instead, this way you end up setting the sign bit, and your corresponding number is -2147483648.

If I run a loop where in each iteration, I do mask >>= 1, following are the mask values, if the starting value was (1<<31) :

-2147483648
-1073741824
-536870912
-268435456
.
.
.
-32
-16
-8
-4
-2
-1
-1
-1
-1
-1
-1
and -1 goes on infinitely.

However, when doing mask /= 2, mask becomes 0 right after -1.
Doing an unsigned mask = (1 << 31) works.


#5

Anshuman Singh OMG Sorry for bothering you. by the way srsly nice work :smiley: (y)