Java ASCII asciiCharToBytes(char[] chars)

Here you can find the source of asciiCharToBytes(char[] chars)

Description

Converts characters from ascii encoded text to a byte[] and zero outs the original char[]

License

LGPL

Parameter

Parameter Description
chars the chars from an ascii encoded text (note - no validation is done to ensure ascii encoding)

Return

the corresponding byte[]

Declaration

public static byte[] asciiCharToBytes(char[] chars) 

Method Source Code

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

public class Main {
    /**//from ww w.j  a v a 2s .c  om
     * Converts characters from ascii encoded text to a byte[] and zero outs the original char[]
     *
     * @param chars the chars from an ascii encoded text (note - no validation is done to ensure ascii encoding)
     * @return the corresponding byte[]
     */
    public static byte[] asciiCharToBytes(char[] chars) {
        byte[] bytes = new byte[chars.length];
        for (int i = 0; i < chars.length; i++) {
            bytes[i] = (byte) chars[i];
            chars[i] = '\0';
        }
        return bytes;
    }
}

Related

  1. ascii2BCD(byte[] val, int len)
  2. AsciiBTAddressToBytes(String btAddress)
  3. asciiBytes(String x)
  4. asciiChar(int value)
  5. asciiChars()
  6. asciiDump(byte[] in)
  7. asciiEbcdic(String source)
  8. asciiEndsWithIgnoreCase(String source, String suffix)
  9. asciiEqualsIgnoreCase(byte[] a, byte[] b)