Java Hex Calculate toHex(int value, int length)

Here you can find the source of toHex(int value, int length)

Description

to Hex

License

Apache License

Declaration

private static String toHex(int value, int length) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static String toHex(int value, int length) {
        char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        StringBuffer buffer = new StringBuffer(length);
        int shift = length - 1 << 2;
        for (int i = -1; ++i < length;) {
            buffer.append(hexDigits[value >> shift & 0xf]);
            value <<= 4;/*from ww  w.  j  a  v a2  s.  c om*/
        }

        return buffer.toString();
    }
}

Related

  1. toHEX(int value)
  2. toHex(int value)
  3. toHex(int value)
  4. toHex(int value, int bits)
  5. toHex(int value, int length)
  6. toHex(int value, int minNumOfDigits)
  7. toHex(long i)
  8. toHex(long i, int r0, boolean r1)
  9. toHex(long l, int length)