转换字节十进制到字节bcd
Conversion byte decimal to byte bcd
我需要将 Delphi 函数转换为 Java 函数。此函数将字节十进制转换为字节 bcd:
function ByteToBCD(Number : byte) : byte;
begin
result:= ((Number div 10) shl 4) or (Number mod 10);
end;
你可以做到
public static int byteToBCD(byte b) {
assert 0 <= b && b <= 99; // two digits only.
return (b / 10 << 4) | b % 10;
}
不清楚你的问题是什么,但答案是琐碎的。
我需要将 Delphi 函数转换为 Java 函数。此函数将字节十进制转换为字节 bcd:
function ByteToBCD(Number : byte) : byte;
begin
result:= ((Number div 10) shl 4) or (Number mod 10);
end;
你可以做到
public static int byteToBCD(byte b) {
assert 0 <= b && b <= 99; // two digits only.
return (b / 10 << 4) | b % 10;
}
不清楚你的问题是什么,但答案是琐碎的。