How can we do this bit level operation in Matlab:
int instructionWord;
a = (instructionWord >>> 21) & 0x1F;
The code right shifts the instructionWord by 21 and obtains the least 5 bits. How can this be equivalently done in Matlab?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Given that your input value is an integer, you could do the following:
Another more bit-like solution would be:
The last method will throw an error if you feed it anything else than intergers.
By the way, your variable instructionWord is declared like a signed integer. But if it is an instruction word or something like that, an unsigned integer would make more sense. The expressions above expect that your input is only positive. If not, it will require a bit more code to model the
>>>(logical right-shift) in matlab.