xor

algorithm to calculate XOR

拜拜、爱过 提交于 2019-12-06 10:55:31
问题 I want to calculate XOR of numbers from 0 to (n)^{1/2} - 1 with each of numbers from 0 to (n)^{1/2} - 1. i want to do this in O(n) time and cant use the XOR, OR, AND operations. If i know the XOR of X and Y, can i calculate XOR of X+1 and Y in constant time? As some have pointed out that XOR can be calculated in constant time using AND and NOT. How do i do the same for AND? How do i calculate AND of numbers from 0 to (n)^{1/2} - 1 with each of numbers from 0 to (n)^{1/2} - 1. i want to do

Increase set of numbers so that XOR sum is 0

我的梦境 提交于 2019-12-06 10:26:22
问题 I need some help with a problem that I have reduced to the following. I have N 30 bit numbers, such that the combined XOR of all of them is non-zero. I need to add a non-negative (0 or more) value to each of the N numbers, such that the combined XOR of the new numbers becomes 0, under the constraint that the total addition value (not the number of additions) is minimized. For example, if I had numbers (01010) 2 , (01011) 2 and (01100) 2 as three numbers (N = 3). Then, their combined XOR is

xor all data in packet

旧街凉风 提交于 2019-12-06 03:57:06
I need a small program that can calculate the checksum from a user input. Unfortunately, all I know about the checksum is that it's xor all data in packet. I have tried to search the net for an example without any luck. I know if I have a string: 41,4D,02,41,21,04,02,02,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 This should result in a checksum of 6A. Hopefully someone could help me. If someone has an example writen in Python 3, could also work for me If i understand "xor all data in packet" correctly, then you should do something like this: #include

Why swap with xor works fine in c++ but in java doesn't ? some puzzle [duplicate]

余生长醉 提交于 2019-12-05 22:14:00
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Why is this statement not working in java x ^= y ^= x ^= y; Sample code int a=3; int b=4; a^=(b^=(a^=b)); In c++ it swaps variables, but in java we get a=0, b=4 why? 回答1: By writing your swap all in one statement, you are relying on side effects of the inner a^=b expression relative to the outer a^=(...) expression. Your Java and C++ compilers are doing things differently. In order to do the xor swap properly,

binary format, bitwise operations exist? eg. <<16#7F, 16#FF>> bsl 1

ⅰ亾dé卋堺 提交于 2019-12-05 20:44:07
问题 In erlang, there are bitwise operations to operate on integers, for example: 1&gt 127 bsl 1. 254 there is also the ability to pack integers into a sequence of bytes &lt&lt 16#7F, 16#FF &gt&gt is it possible, or are there any operators or BIFs that can perform bitwise operations (eg AND, OR, XOR, SHL, SHR) on binary packed data? for example (if bsl worked on binary packages - which it does not): 1&gt &lt&lt 16#7F, 16#FF &gt&gt bsl 1. &lt&lt 255, 254 &gt&gt 回答1: Try out this way: bbsl(Bin,Shift

Maximum XOR value faster than just using XOR

夙愿已清 提交于 2019-12-05 20:43:16
Given a number N and an array of integers (all nos less than 2^15). (A is size of array 100000) Find Maximum XOR value of N and a integer from the array. Q is no of queries (50000) and start, stop is the range in the array. Input: A Q a1 a2 a3 ... N start stop Output: Maximum XOR value of N and an integer in the array with the range specified. Eg: Input 15 2 (2 is no of queries) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 10 6 10 (Query 1) 10 6 10 (Query 2) Output: 13 13 Code: for(int i=start-1;i<stop;i++){ int t =no[i]^a; if(maxxor<t) maxxor=t; } cout << maxxor <<endl; I need a algorithm 10-100 times

How to XOR scramble a string in C and back again with the same function?

心已入冬 提交于 2019-12-05 19:31:13
I am trying to obfuscate a string in a program. Currently, I only have a simple string reversal working. I would like to be able to perform XOR scrambling on the data to make it much more secure, however the method I have tried is not working. The same function and input type is used to decode the string. This is no problem with string reversal, as it just reverses back, but can this be done easily with XORing without getting too complex? I would prefer if the process kept just the one string, like the reversal does. Here is my reversal function. void reverse_string(unsigned char *buf, int

EXCEL XOR multiple bits

北城余情 提交于 2019-12-05 15:42:13
问题 Okay I have two cells with a string of bits 0111010 and 0101011. I want to XOR the two together so that the resulting cell would be 0010001. I know you can use this for boolean values =OR(AND(A1,NOT(A2)),AND(A2,NOT(A1))) but it doesn't work for a string of bits. 回答1: You need to use VBA to do this. If you open VBA, create a new Module and enter the function Public Function BITXOR(x As Long, y As Long) BITXOR = x Xor y End Function You can then use the DEC2BIN and BIN2DEC to convert from

TypeScript interface with XOR, {bar:string} xor {can:number} [duplicate]

大兔子大兔子 提交于 2019-12-05 14:42:31
问题 This question already has answers here : Does Typescript support mutually exclusive types? (4 answers) Closed 3 months ago . How do I say that I want an interface to be one or the other, but not both or neither? interface IFoo { bar: string /*^XOR^*/ can: number; } 回答1: As proposed in this issue, you can use conditional types (introduced in Typescript 2.8) to write a XOR type: type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }; type XOR<T, U> = (T | U) extends object ? (Without

How to generate a random unique string with more than 2^30 combination. I also wanted to reverse the process. Is this possible?

我们两清 提交于 2019-12-05 07:35:22
问题 I have a string which contains 3 elements: a 3 digit code (example: SIN, ABD, SMS, etc) a 1 digit code type (example: 1, 2, 3, etc) a 3 digit number (example: 500, 123, 345) Example string: SIN1500, ABD2123, SMS3345, etc.. I wanted to generate a UNIQUE 10 digit alphanumeric and case sensitive string (only 0-9/a-z/A-Z is allowed), with more than 2^30 (about 1 billion) unique combination per string supplied. The generated code must have a particular algorithm so that I can reverse the process.