2

E.g. I have a file with the following lines:

00000000000000000000000000001000, 00000000000000000000000000000000, 00000000000000000000000000010000, 00000000000000000000000000111000, 00000000000000000000000000110000, 00000000000000000000000001000000,

And I want to see them in hex representation:

0000_0008, 0000_0000, 0000_0010, 0000_0038, 0000_0030, 0000_0040,

Thanks.

3
  • Unless you code something, I suspect that you will have to convert each field individually.
    – Mawg
    Mar 24, 2017 at 7:56
  • Does it have to be a text editor? You save it as a CSV, import into Excel, convert using BIN2HEX, and export as CSV.
    – browly
    Mar 24, 2017 at 20:29
  • @browly, apparently BIN2HEX doesn't work for binary numbers with more than 10 bits.
    – mbmsv
    Mar 27, 2017 at 14:35

1 Answer 1

1

CudaText editor has plugin. It reads current buffer as list of base-2 numbers, writes list of hex to a new tab.

Code of plugin in __init__.py

from cudatext import *

def do_fmt(n):
    s = '%08x'%n
    s = s[:4] + '_' + s[4:]
    return s

class Command:
    def run(self):
        s = ed.get_text_all()

        s = s.replace(' ', ',')
        s = s.replace(';', ',')
        s = s.replace('\n', ',')
        s = s.replace('\t', ',')
        l = s.split(',')

        l = [int(s, 2) for s in l if s]
        l = [do_fmt(n) for n in l]

        out = ', '.join(l)+','

        #put to new tab
        file_open('')
        ed.set_text_all(out)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.