Here you can find the source of asciiCharToBytes(char[] chars)
Parameter | Description |
---|---|
chars | the chars from an ascii encoded text (note - no validation is done to ensure ascii encoding) |
public static byte[] asciiCharToBytes(char[] chars)
//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; } }