I’d love to know the use-case for this. Jim’s put in the most basic response on the how, but I’d like to know the ‘why’. Also are you wanting to get a hex equivalent or the pure binary (AA vs 00000000)? Either way you have to think about encoding, and what you are encoding to/from. As Charlie pointed out, HL7 is an ASCII protocol, but doing anything beyond the basic 127 charset need to know the encoding value (Epic/windows defaults to windows-1252, and a lot of people are turning to UTF-8 as a default ). Figuring out those charsets are… not fun.
Are you trying to capture control characters to start/stop a message or just want a way to encode/decode a string