This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What is this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is this?" Watch "What is this?" New topic
Author

What is this?

Lin Shen
Ranch Hand

Joined: Oct 08, 2003
Posts: 57
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

Joined: May 05, 2000
Posts: 13974
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".


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Lin Shen
Ranch Hand

Joined: Oct 08, 2003
Posts: 57
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

Joined: May 05, 2000
Posts: 13974
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is this?
 
Similar Threads
Download URL for J2EE 1.3 RI
Question48 of Valentin Crettaz's mock exam
another question on arrays
how do we evaluate this???(shift operator)
JSF Components does not appear on the browser