asamra1986
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
if i is the byte given, we can extract bits between n and m where m>=n with the following single instruction.
[i & [(0xFF << m) ^ (0xFF<< n)]] >> n
how this works:
we create 2 maska (Assuming m=5 and n=2)
11100000 0xFF << m
11111100 0xFF << n
Now we take xor of the above which gives us below mask
00011100 [(0xFF << m) ^ (0xFF<< n)]
Now if the apply the & gate with the given byte i (Assuming its 01010101) it gives us below byte.
00010100 [i & [(0xFF << m) ^ (0xFF<< n)]]
Now we can shift the byte n times to the right to get the extracted byte
00000101
-------------------------------------------
Please let me know if you see any improvement or if you have any comment.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
n ^ n will not work. It will always give 0 as an answer for every value of n.
- asamra1986 October 29, 201101010101 n
01010101 n
------------------
00000000 n^n
The truth table of Xor Gate is below
11 0
10 1
01 1
00 0
---------------------------
Please guys lets not argue or use foul language. We all are here to learn.