通过可哈希协议来查看,并使矩阵位置结构符合:
struct MatrixLocation: Hashable { let row: Int let col: Int var hashValue: Int { return row.hashValue ^ col.hashValue } }散列值具有^运算符。
什么是Swift中的^运算符。
提前对这个问题表示歉意。
Looking through the hashable protocol, and to make a matrix location struct to conform:
struct MatrixLocation: Hashable { let row: Int let col: Int var hashValue: Int { return row.hashValue ^ col.hashValue } }The hash value has the ^ operator.
What is the ^ operator in Swift?
最满意答案
^是Swift中的XOR运算符。 基本上它比较两个操作数的位,并且如果两个输入位之一是1 ,而另一个是0 ,则它将每个位设置结果的相应位为1 。 如果两位均为1或两位均为0 ,则将结果中的位设置为0 。
所以如果你有0x49 ^ 0x13 ,那将是01001001 XOR 00010011,它会出现在01011010或0x5a 。
^ is the XOR operator in Swift. Basically it compares the bits of the two operands, and for each bit, it sets the corresponding bit of the result to 1 if one of the two input bits is 1, but the other is 0. If both bits are 1 or both bits are 0, it sets the bit in the result to 0.
So if you have 0x49 ^ 0x13, that would be 01001001 XOR 00010011, which would come out to 01011010, or 0x5a.
^ Swift中的运算符(^ operator in Swift)通过可哈希协议来查看,并使矩阵位置结构符合:
struct MatrixLocation: Hashable { let row: Int let col: Int var hashValue: Int { return row.hashValue ^ col.hashValue } }散列值具有^运算符。
什么是Swift中的^运算符。
提前对这个问题表示歉意。
Looking through the hashable protocol, and to make a matrix location struct to conform:
struct MatrixLocation: Hashable { let row: Int let col: Int var hashValue: Int { return row.hashValue ^ col.hashValue } }The hash value has the ^ operator.
What is the ^ operator in Swift?
最满意答案
^是Swift中的XOR运算符。 基本上它比较两个操作数的位,并且如果两个输入位之一是1 ,而另一个是0 ,则它将每个位设置结果的相应位为1 。 如果两位均为1或两位均为0 ,则将结果中的位设置为0 。
所以如果你有0x49 ^ 0x13 ,那将是01001001 XOR 00010011,它会出现在01011010或0x5a 。
^ is the XOR operator in Swift. Basically it compares the bits of the two operands, and for each bit, it sets the corresponding bit of the result to 1 if one of the two input bits is 1, but the other is 0. If both bits are 1 or both bits are 0, it sets the bit in the result to 0.
So if you have 0x49 ^ 0x13, that would be 01001001 XOR 00010011, which would come out to 01011010, or 0x5a.
发布评论