|
@@ -1,5 +1,7 @@
|
|
|
package cn.hutool.core.codec;
|
|
package cn.hutool.core.codec;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* BCD码(Binary-Coded Decimal)亦称二进码十进数或二-十进制代码<br>
|
|
* BCD码(Binary-Coded Decimal)亦称二进码十进数或二-十进制代码<br>
|
|
|
* BCD码这种编码形式利用了四个位元来储存一个十进制的数码,使二进制和十进制之间的转换得以快捷的进行<br>
|
|
* BCD码这种编码形式利用了四个位元来储存一个十进制的数码,使二进制和十进制之间的转换得以快捷的进行<br>
|
|
@@ -58,6 +60,7 @@ public class BCD {
|
|
|
* @return BCD
|
|
* @return BCD
|
|
|
*/
|
|
*/
|
|
|
public static byte[] ascToBcd(byte[] ascii) {
|
|
public static byte[] ascToBcd(byte[] ascii) {
|
|
|
|
|
+ Assert.notNull(ascii, "Ascii must be not null!");
|
|
|
return ascToBcd(ascii, ascii.length);
|
|
return ascToBcd(ascii, ascii.length);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -68,6 +71,7 @@ public class BCD {
|
|
|
* @return BCD
|
|
* @return BCD
|
|
|
*/
|
|
*/
|
|
|
public static byte[] ascToBcd(byte[] ascii, int ascLength) {
|
|
public static byte[] ascToBcd(byte[] ascii, int ascLength) {
|
|
|
|
|
+ Assert.notNull(ascii, "Ascii must be not null!");
|
|
|
byte[] bcd = new byte[ascLength / 2];
|
|
byte[] bcd = new byte[ascLength / 2];
|
|
|
int j = 0;
|
|
int j = 0;
|
|
|
for (int i = 0; i < (ascLength + 1) / 2; i++) {
|
|
for (int i = 0; i < (ascLength + 1) / 2; i++) {
|
|
@@ -83,6 +87,7 @@ public class BCD {
|
|
|
* @return ASCII字符串
|
|
* @return ASCII字符串
|
|
|
*/
|
|
*/
|
|
|
public static String bcdToStr(byte[] bytes) {
|
|
public static String bcdToStr(byte[] bytes) {
|
|
|
|
|
+ Assert.notNull(bytes, "Bcd bytes must be not null!");
|
|
|
char[] temp = new char[bytes.length * 2];
|
|
char[] temp = new char[bytes.length * 2];
|
|
|
char val;
|
|
char val;
|
|
|
|
|
|