Java Char to Byte Array charToBytes(char[] buffer)

Here you can find the source of charToBytes(char[] buffer)

Description

char To Bytes

License

Open Source License

Declaration

public static byte[] charToBytes(char[] buffer) 

Method Source Code

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

public class Main {
    public static byte[] charToBytes(char[] buffer) {
        byte[] b = new byte[buffer.length << 1];
        for (int i = 0; i < buffer.length; i++) {
            int bpos = i << 1;
            b[bpos] = (byte) ((buffer[i] & 0xFF00) >> 8);
            b[bpos + 1] = (byte) (buffer[i] & 0x00FF);
        }/*from  w  ww . ja  va 2s  . com*/
        return b;
    }
}

Related

  1. charToByteArray(char value)
  2. charToByteArrayBE(char data)
  3. charToBytes(byte[] arr, int offset, char c)
  4. charToBytes(char c)
  5. charToBytes(char c, byte[] arr, int pos)
  6. charToBytes(final char i)