我正在寻找一种将字符串转换为等效 BCD 的方法。我使用 Java,但这确实不是语言的问题。我正在尝试逐步了解如何将字符串转换为 BCD。
例如,假设我有以下字符串;
"0200" (This string has four ASCII characters, if we were in java this string had been contained in a byte[4] where byte[0] = 48, byte[1] = 50, byte[2] = 48 and byte[3] = 48)
在 BCD 中(根据此页面:http ://es.wikipedia.org/wiki/Decimal_codificado_en_binario ):
0 = 0000
2 = 0010
0 = 0000
0 = 0000
好的,我认为转换是正确的,但我必须将其保存在一个字节 [2] 中。我应该怎么做?之后,我必须读取 BCD 并将其转换为原始字符串“0200”,但首先我必须将字符串解析为 BCD。