Question: Given a binary number as a string, x(a binary string), return the binary string of the same length y, that will produce the maximum
Given a binary number as a string, x(a binary string), return the binary string of the same length y, that will produce the maximum value when XORed with x. There is a number of bits that may be set in y called maxSet. Example bits=3 maxSet = 1 x = 101 The binary strings will always have bits digits, and leading zeros are fine. 1. First, determine all possible bits 3 digit binary strings with only maxBits 1 oewer bits set 000, 001, 010, 100. These are the potential values 2. Now, XOR each of the yvalues with x=101 1.000 xor 101-101 2.001 xor 101-100 3.010 xor 101-111 4, 100 xor 101 = 001 The third value produces the maximal result, where y=010. Return the string 010
Step by Step Solution
3.44 Rating (154 Votes )
There are 3 Steps involved in it
Based on the image youve provided it appears you are looking at a coding challenge where you are asked to solve a problem related to binary strings an... View full answer
Get step-by-step solutions from verified subject matter experts
