Two hex and n (0 & lt; n & lt; 31) are input cyclically. hex is a hexadecimal number, what we need to do is to reverse the n-digit hex and output the corresponding results in hexadecimal form to Huawei for an interview; the interview process was neither clear nor checked. As soon as the results passed, the computer was asked to answer questions, which was a little unprepared. I am a front-end Java Web engineer. The basic underlying programming knowledge has long been unfamiliar. The question of this bitwise operation is very simple, and the principle is very clear to the author. However, it has not been used for bitwise operations for many years, java bit operations have never been performed, so the results are really not decent ......
The trial time is set to one hour. The language can be C or Java. It took me nearly three hours to use Java to barely answer the question ...... When I came back, I used JS to implement a simple version. Today, I sorted it out and pasted it.
The question is: cyclically input two numbers in each group hex and n (0 <= n <31). hex is a hexadecimal number, what we need to do is to reverse the nth bit of hex and output the corresponding result in hexadecimal format.
I will not go into details about the process of tossing for more than two hours. The implementation of js is provided here, which is a simple basic bit operation knowledge. The principle is to shift 1 to n places left by bit, and then it is just like the original number or:
Function bitwise (hex, n) {var num = parseInt (hex); num ^ = (1 <
Because the js Integer type is limited to 32 bits, the preceding sample code only supports n <31 (31st bits are signed bits ).