Java Byte Array Create toByteArray(char[] src)

Here you can find the source of toByteArray(char[] src)

Description

to Byte Array

License

Open Source License

Declaration

public static byte[] toByteArray(char[] src) 

Method Source Code

//package com.java2s;
// The MIT License (MIT)

public class Main {
    public static byte[] toByteArray(char[] src) {
        byte[] arr = new byte[src.length * 2];
        for (int i = 0; i < src.length; i++) {
            char chr = src[i];
            arr[i * 2] = (byte) (0xff & (chr >> 8));
            arr[i * 2 + 1] = (byte) (0xff & (chr));
        }//from  w  w  w.j av  a 2 s  .c om
        return arr;
    }
}

Related

  1. toByteArray(byte value)
  2. toByteArray(char c)
  3. toByteArray(char[] charArray)
  4. toByteArray(char[] chars)
  5. toByteArray(char[] chars)
  6. toByteArray(CharSequence hexString)
  7. toByteArray(double[][] array)
  8. toByteArray(final byte[] bytes)
  9. toByteArray(final byte[][] array)