What is Kotlin equivalent for bitwise or with assignment ‘|=’?
There is no built in bitwise-or assignment operator in Kotlin (yet).
There is no built in bitwise-or assignment operator in Kotlin (yet).
|| is the logical-or operator. See here. It evaluates to true if at least one of the operands is true. You can only use it with boolean operands; it is an error to use it with integer operands. // Example var one = true || bar(); // result is true; bar() is never called var … Read more
Maybe writing the values in hexadecimal (or binary) helps 🙂 enum { kCGDisplayBeginConfigurationFlag = (1 << 0), /* 0b0000000000000001 */ kCGDisplayMovedFlag = (1 << 1), /* 0b0000000000000010 */ kCGDisplaySetMainFlag = (1 << 2), /* 0b0000000000000100 */ kCGDisplaySetModeFlag = (1 << 3), /* 0b0000000000001000 */ kCGDisplayAddFlag = (1 << 4), /* 0b0000000000010000 */ kCGDisplayRemoveFlag = (1 … Read more
There isn’t a built-in operator for this, but you can easily simulate the >>> yourself: >>> def rshift(val, n): return val>>n if val >= 0 else (val+0x100000000)>>n … >>> rshift(-1000, 3) 536870787 >>> rshift(1000, 3) 125 The following alternative implementation removes the need for the if: >>> def rshift(val, n): return (val % 0x100000000) >> … Read more
Unless you’re using an ancient compiler, it can already handle this level of conversion on its own. That is to say, a modern compiler can and will implement i % 2 using a bitwise AND instruction, provided it makes sense to do so on the target CPU (which, in fairness, it usually will). In other … Read more
You need to ask Brian Kernighan or Dennis Ritchie. From this forum: http://bytes.com/topic/c/answers/167377-operator-precedence The && and || operators were added later for their “short-circuiting” behavior. Dennis Ritchie admits in retrospect that the precedence of the bitwise operators should have been changed when the logical operators were added. But with several hundred kilobytes of C source … Read more
He meant that taking number mod 2^n is equivalent to stripping off all but the n lowest-order (right-most) bits of number. For example, if n == 2, number number mod 4 00000001 00000001 00000010 00000010 00000011 00000011 00000100 00000000 00000101 00000001 00000110 00000010 00000111 00000011 00001000 00000000 00001001 00000001 etc. So in other words, number … Read more
Numbers can be expressed in binary like this: 3 = 000011 5 = 000101 10 = 001010 …etc. I’m going to assume you’re familiar with binary. Bitwise AND means to take two numbers, line them up on top of each other, and create a new number that has a 1 where both numbers have a … Read more
You can convert the characters to integers and xor those instead: l = [ord(a) ^ ord(b) for a,b in zip(s1,s2)] Here’s an updated function in case you need a string as a result of the XOR: def sxor(s1,s2): # convert strings to a list of character pair tuples # go through each tuple, converting them … Read more
x << -n is equal to x << (32 – n) ~3 == -4 so 5 << ~3 === 5 << (32 – 4) === 5 << 28 which is 1,342,177,280 to be accurate X << -n is not the same as X << (32 – n) … in fact it’s both simpler and more … Read more