when we went to Huawei for an interview. Not ready for work. The process of the interview did not ask clear also did not check, the results of a past let on the machine to do the problem, really a bit unprepared. The author is good at the front-end Java WebProject Division, the main underlying programming knowledge has long been unfamiliar. Machine test questions encountered this bit operation of the topic, supposedly is very easy, the principle of the author is also very clear. However, because it is really good for many years not to engage in bit arithmetic, the Java bit operation is not operational. So the result is really not decent ...
The machine test time is one hours. Language optional C or Java also has a scripting language, the author spent nearly three hours. Only in Java reluctantly to make the problem. Shame and shame ... Come back with JS once again implemented a simple version number. Put it together today.
The title is: loop input each group of two number hex and N (0<=n<31), Hex is a 16 decimal number, we have to do is to take the nth position of hex counter. The corresponding results are then output in 16 binary form.
I toss two hours of the process will not repeat, here to give the realization of JS. Very easy-to-operate basic knowledge. The principle of a wordy sentence. is to shift the 1 to the left n bit by bit and then to the original number:
function Bitoper (hex, N) { var num = parseint (hex); Num ^= (1<<n); return num.tostring (16);} Console.log (Bitoper (0x1234, 3)); 123c
because the JS integer type has only 32-bit limitations, the Demo sample code above only supports the simple case of n<31 (the 31st bit is the sign bit).
Specific bit inversion (JS implementation)