Sharon writes:
>
> What does this mean? What is 0xf?
>
> char c;
> c = (char) ((x >> 4) & 0xf);
>
>
> -Sharon
>

char c;   -  means to declare variable 'c' of type 'char' (usually
             means an 8-bit wide variable)

x >> 4    -  means to shift the variable 'x' to the right 4 places
             (which is basically saying divide it by 16)

0xf       -  is hexidecimal 'f' or decimal 15 or binary 1111

& 0xf     -  is using '0xf' as what is called a mask.  The '&'
             means to do a boolean AND function.  In this case,
             they are only interested in the 4 least significant
             bits of 'x' so they AND it with '0xf' which contains
             all zero's except the four least significant bits.
             Anything AND'ed with zero is zero.

(char)    -  Means to 'cast' the final answer to be of type 'char'.

So as an example, lets say:
   x = 319 (decimal) = 0x13f (hex) = 0000000100111111 (binary)

shifting right 4 places (x >> 4) =
   0000000000010011 = 0x0013 = 19 (dec)

masking off the upper 12 bits ( & 0xf) =
     0000000000010011
  &  0000000000001111  (the '0xf' mask)
---------------------
     0000000000000011  = 0x0003 = 3 (dec)

Therefore 'c' = 0x03.


-Kevin

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to