Here you can find the source of toBytes(char value)
public static byte[] toBytes(char value)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] toBytes(char value) { byte[] bt = new byte[2]; for (int i = 0; i < bt.length; i++) { bt[i] = (byte) (value >>> i * 8); }//from w w w.j ava2 s . com return bt; } public static byte[] toBytes(short value) { byte[] bt = new byte[2]; for (int i = 0; i < bt.length; i++) { bt[i] = (byte) (value >>> i * 8); } return bt; } public static byte[] toBytes(int value) { byte[] bt = new byte[4]; for (int i = 0; i < bt.length; i++) { bt[i] = (byte) (value >>> i * 8); } return bt; } public static byte[] toBytes(long value) { byte[] bt = new byte[8]; for (int i = 0; i < bt.length; i++) { bt[i] = (byte) (int) (value >>> i * 8); } return bt; } }