我最近编写了一个脚本,该脚本解析了单个二进制字节月字段的文本表示.
(不要问: - {)
在摆弄sprintf一段时间之后,我放弃了并做了这件事;
our %months = qw / x01 1
x02 2
x03 3
x04 4
x05 5
x06 6
x07 7
x08 8
x09 9
x0a 10
x0b 11
x0c 12 /;
...
my $month = $months{$text};
Run Code Online (Sandbox Code Playgroud)
我侥幸逃脱,因为我只使用12个数字,但是有更好的方法吗?
如何用八进制表示打印字符?请注意,这些字符可能是特殊字符(转义,背景,箭头键).
例如,我想要一个函数'printoctal',这样:
my $char='P';
printoctal $char;
Run Code Online (Sandbox Code Playgroud)
我想打印一下 120
我在hexdump代码中有一些数据.左手是DEC,右手是hexdump代码.
16 = 10
51 = 33
164 = A4 01
388 = 84 03
570 = BA 04
657 = 91 05
1025 = 81 08
246172 = 9C 83 0F
Run Code Online (Sandbox Code Playgroud)
如何计算到DEC的任何hexdump?在perl中,我尝试使用ord()命令但不起作用.
更新 我不知道它叫什么.它看起来像7bits数据.我尝试在excel中构建公式,如下所示:
DEC = hex2dec(X) + (128^1 * hex2dec(Y-1)) + (128^2 * hex2dec(Z-1)) + ...
Run Code Online (Sandbox Code Playgroud)