Java ASCII to String asciiToString(byte ascii)

Here you can find the source of asciiToString(byte ascii)

Description

ascii To String

License

Apache License

Declaration

static String asciiToString(byte ascii) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    static String asciiToString(byte ascii) {
        switch (ascii) {
        case (int) '\n':
            return "\\n";
        case (int) '\t':
            return "\\t";
        case 11://from   w w  w.ja  v  a  2s.  com
            return "\\v";
        case 7:
            return "\\a";
        case 8:
            return "\\b";
        case 13:
            return "\\r";
        case 12:
            return "\\f";
        case (int) '\\':
            return "\\\\";
        case (int) '\'':
            return "\\\'";
        case (int) '\"':
            return "\\\"";
        case 0:
            return "\\0";
        default:
            if (32 <= ascii && ascii <= 126) {
                // Printable ascii character.
                return (new Character((char) ascii)).toString();
            } else {
                int high = (ascii & 0xF0) >>> 4;
                int low = ascii & 0xF;
                char highchar = (char) (high < 10 ? high + (int) '0' : high - 10 + (int) 'A');
                char lowchar = (char) (low < 10 ? low + (int) '0' : low - 10 + (int) 'A');
                char[] temp = { '\\', 'x', highchar, lowchar };
                return new String(temp);
            }
        }
    }
}

Related

  1. asciiBytesToChar(byte[] bytes)
  2. asciiBytesToString(byte[] val)
  3. ASCIIToChar(final int ascii)
  4. AsciiToChar(int asc)
  5. asciiToLowerCase(String s)
  6. asciiToString(byte[] b, int off, int len)
  7. asciiToString(int asciiCode)
  8. asciiTrimR(String str, int length)