Java Byte to ASCII byteToASCII(final byte b)

Here you can find the source of byteToASCII(final byte b)

Description

Convert a byte to a character representation.

License

Open Source License

Parameter

Parameter Description
b the byte to convert

Return

the ASCII character representation of the byte

Declaration

public static char byteToASCII(final byte b) 

Method Source Code

//package com.java2s;
/*/*ww w . ja va 2  s  .co m*/
 * Copyright (c) 2014 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial API and implementation
 */

public class Main {
    /**
     * Convert a byte to a character representation.
     *
     * <p>Sorta misnamed as this method will return the character representation
     * of the given byte in the current / default encoding for the locale.
     *
     * @param b the byte to convert
     *
     * @return the ASCII character representation of the byte
     */
    public static char byteToASCII(final byte b) {
        if ((b < 32) || (b > 126)) {
            return ' ';
        } else {
            return (char) b;
        }
    }
}

Related

  1. byteToASCII(final byte b)
  2. byteToAscii(final byte byteToAscii)
  3. byteToAscii(int val)