xor

Javascript & PHP Xor equivalent

别等时光非礼了梦想. 提交于 2019-12-11 17:22:07
问题 I have a javascript code: var c = 267414715; var d = c ^ ("0x81BE16CD"); Result is -1907459466 http://jsfiddle.net/4N3JY/1/ I can't seem to get a PHP equivalent. Have tried the following: <?php $c=267414715; $d=$c ^ hexdec("0x81BE16CD"); echo "With hexdec: $d\n"; $d=$c ^ base_convert("0x81BE16CD", 16, 2); echo "With base_convert(2): $d\n"; $d=$c ^ base_convert("0x81BE16CD", 16, 10); echo "With base_convert(10): $d\n"; ?> Output: With hexdec: 2387507830 With base_convert(2):

Count all pairs with given XOR

混江龙づ霸主 提交于 2019-12-11 16:58:12
问题 Given a list of size N. Find the number of pairs (i, j) such that A[i] XOR A[j] = x, and 1 <= i < j <= N. Input : list = [3, 6, 8, 10, 15, 50], x = 5 Output : 2 Explanation : (3 ^ 6) = 5 and (10 ^ 15) = 5 This is my code (brute force): import itertools n=int(input()) pairs=0 l=list(map(int,raw_input().split())) q=[x for x in l if x%2==0] p=[y for y in l if y%2!=0] for a, b in itertools.combinations(q, 2): if (a^b!=2) and ((a^b)%2==0) and (a!=b): pairs+=1 for a, b in itertools.combinations(p,

Bitwise xor python

断了今生、忘了曾经 提交于 2019-12-11 16:03:05
问题 I am trying to solve a problem where I have to decrypt a file. But I found an obstacle. As you can see in the below code, I need to do a bitwise xor between key and number 47. from Crypto.Cipher import AES import base64 l1 = open("./2015_03_13_mohamed.said.benmousa.puerta_trasera.enc", "rb"); iv = l1.read(16) enc = l1.read() l1.close() #key = xor beetwen kiv(47) and IV key = iv for i in range(len(key)): key[i] = key[i] ^ 47 obj = AES.new(key,AES.MODE_CBC, iv) obj1 = obj.decrypt(enc) l = open(

How to define an xor operator in Io

偶尔善良 提交于 2019-12-11 12:26:50
问题 I'm working through Chapter 3, Day to of Seven Languages in Seven Weeks ("The Sausage King"). I've copied the code straight out of the book, but it's not working. Io 20110905 Add a new operator to the OperatorTable. Io> OperatorTable addOperator("xor", 11) ==> OperatorTable_0x336040: Operators 0 ? @ @@ 1 ** 2 % * / 3 + - 4 << >> 5 < <= > >= 6 != == 7 & 8 ^ 9 | 10 && and 11 or xor || 12 .. 13 %= &= *= += -= /= <<= >>= ^= |= 14 return Assign Operators ::= newSlot := setSlot = updateSlot To add

Join Clause With a XOR Statement

天涯浪子 提交于 2019-12-11 08:28:26
问题 I am doing a join and I can't seem to make this XOR to properly work. SELECT t1.COMPANY, t1.MILES, CASE WHEN t2.MILES IS NULL THEN t3.MILES ELSE t2.MILES END AS MILES2, CASE WHEN t2.MILES = t1.MILES AND t2.MILES != 9999 THEN t2.FLATRATE ELSE t3.RATEBASIS END AS RATE FROM TABLE1 AS t1 LEFT JOIN TABLE2 AS t2 ON t1.[COMPANY] = t2.[COMPANYCODE] AND (t1.[MILES] = t2.[MILES]) INNER JOIN ( SELECT TOP 1 TRUCKERCODE, MILES, RATEBASIS, FLATRATE FROM TABLE2 WHERE MILES = 9999 ) AS t3 ON t1.[COMPANY] =

How to implement an XOR Linked List in Python?

 ̄綄美尐妖づ 提交于 2019-12-11 07:06:00
问题 Given that python objects are only a reference to the actual memory Objects and memory address of objects cannot be retrived. Is it possible to implement an XOR linked list in Python ? if yes how ? 回答1: You can't build an XOR linked list in Python, since Python doesn't let you mess with the bits in pointers. You don't want to implement that anyway -- it's a dirty trick that makes your code hard to understand for little benefit. If you're worried about memory, it's almost always better to use

Cython implementation no faster than pure python

天大地大妈咪最大 提交于 2019-12-11 06:46:41
问题 For an exercise I've written a XOR doubly-linked list %%cython from cpython.object cimport PyObject from cpython.ref cimport Py_XINCREF, Py_XDECREF from libc.stdint cimport uintptr_t cdef class Node: cdef uintptr_t _prev_xor_next cdef object val def __init__(self, object val, uintptr_t prev_xor_next=0): self._prev_xor_next=prev_xor_next self.val=val @property def prev_xor_next(self): return self._prev_xor_next @prev_xor_next.setter def prev_xor_next(self, uintptr_t p): self._prev_xor_next=p

Python XOR preference: bitwise operator vs. boolean operators [duplicate]

与世无争的帅哥 提交于 2019-12-11 05:34:16
问题 This question already has answers here : Boolean operators vs Bitwise operators (9 answers) How do you get the logical xor of two variables in Python? (22 answers) Closed 3 years ago . Is there a preferred method for doing a logical XOR in python? For example, if I have two variables a and b, and I want to check that at least one exists but not both, I have two methods: Method 1 (bitwise operator): if bool(a) ^ bool(b): do x Method 2 (boolean operators): if (not a and b) or (a and not b): do

Three-way xor-like function

丶灬走出姿态 提交于 2019-12-11 04:09:13
问题 I'm trying to solve the following puzzle: Given a stream of numbers (only 1 iteration over them is allowed) in which all numbers appear 3 times, but 1 number appear only 2 times, find this number, using O(1) memory. I started with the idea that, if all numbers appeared 2 times, and 1 number only once, I could use xor operation between all numbers and the result would be the incognito number. So I want to extend this idea to solve the puzzle. All I need is a xor-like function (or operator),