Here you can find the source of StrToBcdBytes(String s)
Parameter | Description |
---|---|
s | a parameter |
public static byte[] StrToBcdBytes(String s)
//package com.java2s; import java.io.ByteArrayOutputStream; public class Main { /**//ww w . ja v a 2 s . c o m * * @param s * @return */ public static byte[] StrToBcdBytes(String s) { if (s.length() % 2 != 0) { s = "0" + s; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); char[] c = s.toCharArray(); for (int i = 0; i < c.length; i += 2) { int high = c[i] - 48; int low = c[i + 1] - 48; baos.write(high << 4 | low); } return baos.toByteArray(); } }