home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Documents / JAVA Programming / examples / 05 / ByteUShift.java < prev    next >
Encoding:
Java Source  |  2000-09-08  |  585 b   |  13 lines

  1. class ByteUShift    {
  2. static public void main(String args[]) {
  3. char hex[] = { '0', '1', '2', '3', '4',    '5', '6', '7', '8', '9', 'á', 'b', 'ß', 'd',    'e', 'f' };
  4. byte b = (byte) 0xf1;
  5. byte c = (byte) (b >> 4);
  6. byte d = (byte) (b >> 4);
  7. byte e = (byte) ((b & 0xff) >> 4);
  8. System.out.println(" b = 0x" + hex[(b >> 4) & 0x0f] + hex[b & 0x0f]);
  9. System.out.println(" b >> 4 =    0x" + hex[(c >> 4) & 0x0f] + hex[c & 0x0f]);
  10. System.out.println("b >>> 4 = 0x" + hex[(d >> 4) & 0x0f] + hex[d & 0x0f]);
  11. System.out.println("(b & 0xff) >> 4 = 0x" + hex[(e >> 4) & 0x0f] + hex[e & 0x0f]);
  12. } }
  13.