Java Hex Print printHex(byte b)

Here you can find the source of printHex(byte b)

Description

print Hex

License

Open Source License

Declaration

private static void printHex(byte b) 

Method Source Code

//package com.java2s;
/*/* www. j a v  a 2 s  .  c om*/
 * $RCSfile: FPXUtils.java,v $
 *
 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
 *
 * Use is subject to license terms.
 *
 * $Revision: 1.1 $
 * $Date: 2005/02/11 04:55:41 $
 * $State: Exp $
 */

public class Main {
    private static void printHex(byte b) {
        int i = b & 0xff;
        int hi = i / 16;
        int lo = i % 16;

        if (hi < 10) {
            System.out.print((char) ('0' + hi));
        } else {
            System.out.print((char) ('a' + hi - 10));
        }

        if (lo < 10) {
            System.out.print((char) ('0' + lo));
        } else {
            System.out.print((char) ('a' + lo - 10));
        }
    }
}

Related

  1. printHex(byte[] array)
  2. printHex(byte[] array, int offset, int len)
  3. printHex(byte[] b)
  4. printHex(byte[] bytes)