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

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

Description

chars To Bytes

License

Open Source License

Declaration

public static final byte[] charsToBytes(char[] chars) 

Method Source Code

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

public class Main {
    public static final byte[] charsToBytes(char[] chars) {
        byte[] b = new byte[chars.length << 1];
        for (int i = 0; i < chars.length; i++) {
            char strChar = chars[i];
            int bpos = i << 1;
            b[bpos] = (byte) ((strChar & 0xFF00) >> 8);
            b[bpos + 1] = (byte) (strChar & 0x00FF);
        }//from www .ja  va 2  s  .c  o  m
        return b;
    }
}

Related

  1. charArrayToByteArray(char[] value)
  2. charArrayToByteArray(final char[] message)
  3. charArrayToBytes(char[] chars)
  4. chars2Bytes(char[] chars)
  5. chars2Bytes(char[] chars)
  6. charsToBytes(char[] chars)
  7. charsToBytes(char[] in)
  8. charsToBytes(final char[] chars, final int charOffset, final int length, final byte[] bytes, final int byteOffset)
  9. ConvertCharArrayToByteArray(char value[])