1

有没有一种简单的方法可以使用 vim 将以下十六进制值转换为二进制表示。

00ab abcd ff01 1234

它应该看起来像。

0000000010101011 1010101111001101 1111111100000001 0001001000110100

4

1 回答 1

5

Run both of these commands and it should convert the line from hex to binary. The first line just creates a lookup table for the 16 hexadecimal digits that returns its binary representation. The second line finds all hexadecimal digits and replaces it with the value returned from the lookup table.

:let t = {'0':'0000', '1':'0001', '2':'0010', '3':'0011', '4':'0100', '5':'0101', '6':'0110', '7':'0111', '8':'1000', '9':'1001', 'a':'1010', 'b':'1011', 'c':'1100', 'd':'1101', 'e':'1110', 'f':'1111'}
:s/\x/\=t[tolower(submatch(0))]/g
于 2013-10-04T13:30:25.787 回答