c# - Show binary code of external files/program -
one way or another, digital data stored in 0 , 1. that's principle of binary data, guess.
is there method or package can show binary code of file/single-exe-program of how being stored in 0/1 format??
i see like: - import certain, random file - convert it's 0/1 format - store the 1/0-data in txt (streamwriter/binarywriter)
if yes, available in .net language (pref: c#)?
essentially need break 2 steps:
- convert file bytes
- convert byte binary string
var filebytes = file.readallbytes(somefilename);
the second step less straightforward, but still pretty easy:
var bytestring = string.concat(filebytes.select(x => convert.tostring(x, 2).padleft(8, '0')))
the idea here select each byte individually, converting each 1 binary string (pad left each 1 8 characters, since many bytes have leading zeroes), , concatenate of single string. (courtesy in part of @xanatos' comment below.)
Comments
Post a Comment