@yuanliu 01100011 was _not_ hex. It was binary for 0x63. That's why I'm completely confused by @PickleRick Lol you wouldn't believe how much time I spent trying to decipher the OP's intent from...
See more...
@yuanliu 01100011 was _not_ hex. It was binary for 0x63. That's why I'm completely confused by @PickleRick Lol you wouldn't believe how much time I spent trying to decipher the OP's intent from the various posted replies to everybody's attempt to help. After hours of scrolling up and down, back and forth, I distilled the instructions into the following algorithm given an even numbered HEX string, e.g., aabbcc Break the string into 2-HEX chunks. (OP used the term 2-bytes - I realize that is actually 4-bytes) Convert each chunk into binary. Reverse the order of the binary chunks. Count the positions of nonzero bits of the full reversed binary string from the right. (As I said, I can't think of a practical purpose of this exercise. By the way, to anyone who is going to ask a question here, even though I strongly encourage describing problem without SPL first, please make the description as algorithmic as possible.) As a weird game, this applies to any even-length HEX string. Here's a sequence of up to 16 HEX characters. hex padded_binary nonzero_bits 01 00000001 0 0002 00000010 00000000 9 000003 00000011 00000000 00000000 16 17 00000004 00000100 00000000 00000000 00000000 26 0000000005 00000101 00000000 00000000 00000000 00000000 32 34 000000000006 00000110 00000000 00000000 00000000 00000000 00000000 41 42 00000000000007 00000111 00000000 00000000 00000000 00000000 00000000 00000000 48 49 50 0000000000000008 00001000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 59 90000000000000 00000000 00000000 00000000 00000000 00000000 00000000 10010000 4 7 a00000000000 00000000 00000000 00000000 00000000 00000000 10100000 5 7 b000000000 00000000 00000000 00000000 00000000 10110000 4 5 7 c0000000 00000000 00000000 00000000 11000000 6 7 d00000 00000000 00000000 11010000 4 6 7 e000 00000000 11100000 5 6 7 f0 11110000 4 5 6 7 Another thing I realize is that I must handle 2-HEX (single-chunk) specially. Here is the emulation code | makeresults format=csv data="hex
01
0002
000003
00000004
0000000005
000000000006
00000000000007
0000000000000008
90000000000000
a00000000000
b000000000
c0000000
d00000
e000
f0"
``` data emulation above ```
| eval idx = mvrange(0, len(hex) / 2)
| eval reverse2hex = mvreverse(mvmap(idx, substr(hex, idx*2 + 1, 2)))
| eval ASbinary=if(idx < 1, tostring(tonumber(reverse2hex,16),"binary"), mvmap(reverse2hex, tostring(tonumber(reverse2hex,16),"binary")))
| eval padded_binary = if(idx < 1, printf("%08d", ASbinary), mvmap(ASbinary, printf("%08d", ASbinary)))
| eval reverse_bits = mvreverse(mvmap(padded_binary, split(padded_binary, ""))), position = -1
| foreach reverse_bits mode=multivalue
[eval position = position + 1, nonzero_bits = if(<<ITEM>> == 0, nonzero_bits, mvappend(nonzero_bits, position))]
| fields hex padded_binary nonzero_bits (Technically this works for odd number of HEX characters, too, if OP can define where to split.)