• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is this?

 
Lin Shen
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw an operaton and I could not understand it. Could you tell me what this is?
int ir;
opcode = (ir >> 26) & 0x3f;
subfunct = ir & 0x3f;
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a compile error. ir needs to be initialized before you can use it.
Ignoring that...
opcode = (ir >> 26)
This is a right shift. Shift all the bits 26 bits to the right.
& 0x3f;
Now 'and" the result of the shift with the hexidecimal number "3F" and store it the field "opcode".

subfunct = ir & 0x3f
Now take ir and "and" it with the hexidecimal number "3F".
 
Lin Shen
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. Thanks a lot.
Now I have a 32 bits binary number, which is represented as hexadecimal number stored in variable ir. What can I do if I want to get the 21-26 bits of this binary number?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on what you mean by "get". How do you want to get them? What do you want to do with them?
You can isolate them in their own int by "anding" all the other bits out and then shifting.
Lets say I have:
0000 1010 1010 1010 1010 1010 1010 1010
and I want just bits 21-26, I can "and" it with 0xFC0:
0000 1010 1010 1010 1010 1010 1010 1010
0000 0000 0000 0000 0000 1111 1100 0000
---------------------------------------
0000 0000 0000 0000 0000 1010 1000 0000
You can then shift it 6 bits to the right.

i will contain 42.
[ November 05, 2003: Message edited by: Thomas Paul ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic