Java Hex Calculate toHexChar(char ch, StringBuffer sb)

Here you can find the source of toHexChar(char ch, StringBuffer sb)

Description

to Hex Char

License

BSD License

Declaration

public static void toHexChar(char ch, StringBuffer sb) 

Method Source Code

//package com.java2s;
//The contents of this file are subject to the "Simplified BSD License" (the "License");

public class Main {
    public static void toHexChar(char ch, StringBuffer sb) {
        if ((ch & 0xFF00) != 0)
            toHexByte((byte) ((ch >> 8) & 0xFF), sb);
        toHexByte((byte) (ch & 0xFF), sb);

    }// w  ww  .j  ava2 s  . com

    public static void toHexByte(byte b, StringBuffer sb) {
        int n1 = (b & 0xF0) >> 4;
        int n2 = (b & 0xF);
        sb.append((char) (n1 < 10 ? n1 + '0' : (n1 - 10) + 'A'));
        sb.append((char) (n2 < 10 ? n2 + '0' : (n2 - 10) + 'A'));

    }
}

Related

  1. toHexByteArray(final byte[] buffer)
  2. toHexBytes(byte[] bytes)
  3. toHexBytes(byte[] data)
  4. toHexBytes(byte[] toBeConverted)
  5. toHexChar(byte[] bArray)
  6. toHexChar(int b)
  7. toHexChar(int digit)
  8. toHexChar(int digitValue)
  9. toHexChar(int digitValue)