Java Char Array to Byte Array convertCharsToBytes(char[] chars)

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

Description

convert Chars To Bytes

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] convertCharsToBytes(char[] chars) {
        byte[] result = new byte[chars.length * 2];

        for (int i = 0; i < chars.length; ++i) {
            result[2 * i] = (byte) (chars[i] / 256);
            result[2 * i + 1] = (byte) (chars[i] % 256);
        }/*www. j  a v a  2s  . co  m*/

        return result;
    }
}

Related

  1. charsToBytes(char[] chars)
  2. charsToBytes(char[] chars)
  3. charsToBytes(char[] in)
  4. charsToBytes(final char[] chars, final int charOffset, final int length, final byte[] bytes, final int byteOffset)
  5. ConvertCharArrayToByteArray(char value[])
  6. convertCharsToBytes(char[] chars)