2's complement
Understanding 's complement representation is fundamental to learning about Computer Science. It allows us to write negative numbers in binary. The leftmost digit is used as a sign bit. If it is , we have a negative number and it is represented as the two's complement of its absolute value. Let's say you wrote down the 's complement representation for each -bit integer in the inclusive range from to . How many 's would you write down in all? For example, using an -bit byte rather than bit i
View Solution →Changing Bits
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed: set_a idx x: Set to , where and is least significant bit of . set_b idx x: Set to , where and is least significant bit of . get_c idx: Print , where and . Given , and a list of commands, create a string made of the results of each call, the only command that produces output. For example, and so the length of the numbers is . Print an answer string that contains the results of a
View Solution →XOR key
Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This encryption algorithm uses a sequence of non-negative integers as its key. To implement this algorithm efficiently, Xorq needs to find maximum value of for given integers , and , such that, . Help Xorq implement this function. For example, , , and . We test each for all values of between and inclusive: Function Description Complete the xorKey function in the editor below. It should ret
View Solution →Maximizing the Function
Consider an array of binary integers (i.e., 's and 's) defined as . Let be the bitwise XOR of all elements in the inclusive range between index and index in array . In other words, . Next, we'll define another function, : Given array and independent queries, perform each query on and print the result on a new line. A query consists of three integers, , , and , and you must find the maximum possible you can get by changing at most elements in the array from to or from to . No
View Solution →XOR Subsequences
onsider an array, , of integers (). We take all consecutive subsequences of integers from the array that satisfy the following: For example, if our subsequences will be: For each subsequence, we apply the bitwise XOR () operation on all the integers and record the resultant value. Since there are subsequences, this will result in numbers. Given array , find the XOR sum of every subsequence of and determine the frequency at which each number occurs. Then print the number and its res
View Solution →