不用转.字节数组本身就是二进制的了.
数据库存的是什么类型?
c#的转化函数是
byte[] bs = new byte[] { 0x00, 0x00, 0x00, 0x3F }; int i = BitConverter.ToInt32(bs, 0); float f = BitConverter.ToSingle(bs, 0);
数据库存的是十六进制的字节数组
java中例子:
public class Hex2Binary{ public static void main(String[] args) { String hexString = "ABCD"; System.out.println(hexString2binaryString(hexString)); } public static String hexString2binaryString(String hexString) { if (hexString == null || hexString.length() % 2 != 0) return null; String bString = "", tmp; for (int i = 0; i < hexString.length(); i++) { tmp = "0000"+Integer.toBinaryString(Integer.parseInt(hexString .substring(i, i + 1), 16)); bString += tmp.substring(tmp.length() - 4); } return bString; } }
不用转