将二进制字符串转换为十六进制以进行卷曲请求

时间:2018-11-20 19:01:30

标签: python curl hex binarystream

我有一个

这样的结构包
def encode_number(value):
    return struct.pack('>I', value)


def decode_number(raw):
    return int.from_bytes(raw, byteorder='big') 

>>> encode_number(1) b'\x00\x00\x00\x01'

>>> decode_number(b'\x00\x00\x00\x01') 1

而通过curl给出的交易以十六进制形式给出 curl http://localhost:26657/broadcast_tx_commit?tx=0x01

所以0x01的十六进制为1,如何使用curl命令将二进制字符串轻松转换为十六进制? (最好在Linux终端中使用)

1 个答案:

答案 0 :(得分:0)

只是做了一次Google搜索,就发现了这一点: https://unix.stackexchange.com/questions/65280/binary-to-hexadecimal-and-decimal-in-a-shell-script

它们用于二进制到十六进制(Bash / Linux终端)的示例:

%macro simple(x=);
    %global value;
    %let value = %sysfunc(intnx(month, %sysfunc(today()), &x, same)); 
    %put &value;
%mend simple;
%simple(x=1);

data have;
    do x = 1 to 15;
        output;
    end;
run;

data want;
    data have;
        newdate = %simple(x);
run;