From 1d6c5111cf4aafc076aa3f8ddf488f6cc3cf6cb1 Mon Sep 17 00:00:00 2001 From: Junjie <xjj@123> Date: 星期四, 13 二月 2025 16:56:11 +0800 Subject: [PATCH] # --- src/main/java/com/zy/common/utils/CommonUtils.java | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/zy/common/utils/CommonUtils.java b/src/main/java/com/zy/common/utils/CommonUtils.java index d42d922..411cc44 100644 --- a/src/main/java/com/zy/common/utils/CommonUtils.java +++ b/src/main/java/com/zy/common/utils/CommonUtils.java @@ -40,6 +40,10 @@ return new short[]{byteToShort, byteToShort2}; } + public static boolean intToBoolean(Integer num) { + return num != 0; + } + public static boolean shortToBoolean(Short num) { return num != 0; } @@ -64,4 +68,31 @@ return sb.toString(); } + public static int[] byteToBits(byte by) { + StringBuffer sb = new StringBuffer(); + sb.append((by >> 0) & 0x1); + sb.append((by >> 1) & 0x1); + sb.append((by >> 2) & 0x1); + sb.append((by >> 3) & 0x1); + sb.append((by >> 4) & 0x1); + sb.append((by >> 5) & 0x1); + sb.append((by >> 6) & 0x1); + sb.append((by >> 7) & 0x1); + + int[] data = new int[8]; + for (int i = 0; i < sb.length(); i++) { + data[i] = Integer.parseInt(String.valueOf(sb.charAt(i))); + } + + return data; + } + + public static String bytesToBarcode(byte[] bytes) { + StringBuffer sb = new StringBuffer(); + for (byte by : bytes) { + sb.append(by); + } + return sb.toString(); + } + } -- Gitblit v1.9.1