|
|
 |
RE: FN-FORUM the operator >>
date posted 15th January 2002 16:09
The answer is below
Shift operators
The shift operators also manipulate bits. They can be used solely with
primitive, integral types. The left-shift operator ( < > ) produces the operand to the
left of the operator shifted to the right by the number of bits specified
after the operator. The signed right shift > > uses sign extension: if the
value is positive, zeroes are inserted at the higher-order bits; if the
value is negative, ones are inserted at the higher-order bits. Java has also
added the unsigned right shift > > > , which uses zero extension: regardless
of the sign, zeroes are inserted at the higher-order bits. This operator
does not exist in C or c++.
If you shift a char, byte, or short, it will be promoted to int before the
shift takes place, and the result will be an int. Only the five low-order
bits of the right-hand side will be used. This prevents you from shifting
more than the number of bits in an int. If you're operating on a long,
you'll get a long result. Only the six low-order bits of the right-hand side
will be used so you can't shift more than the number obits in a long.
Shifts can be combined with the equal sign ( «= or »= or »>=). The lvalue is
replaced by the lvalue shifted by the rvalue. There is a problem, however,
with the unsigned right shift combined with assignment. If you use it with
byte or short you don't get the correct results. Instead, these are promoted
to int and right shifted, but then truncated as they are
Regards
Darren Spink
http://www.arkad.co.uk
Tel: +44(0)113 253 4750
Fax: +44(0)113 253 1686
ICQ: 56667649
-----Original Message-----
From: [EMAIL REMOVED]
[EMAIL REMOVED] Behalf Of marco polo
Sent: 15 January 2002 09:19
To: [EMAIL REMOVED]
Subject: FN-FORUM the operator >>
hi there,
i don't know where to ask this question in java newsgroups and i hope this
mailing list will help.
i'm a java newbie and have frequently come across codes like this:
int r=(colorval >> 16) & 0xff;
int g=(colorval >> 8) & 0xff;
int b= colorval & 0xff;
can anybody here explain how this operator work?
marco
Send and receive Hotmail on your mobile device: Click Here
============================================================ * Free listing
for freelancers * Free to advertise jobs * Free jobs distribution service *
Free database of 5000 freelancers Freelancers and Freelance Jobs:
http://www.freelancers.net Forum FAQs: http://freelancers.netrickery.com To
unsubscribe please email:
[EMAIL REMOVED] If you have
difficulties unsubscribing please email: [EMAIL REMOVED]
|
 |
|