back

by Narishma·11y ago·view on hn ↗
From the C Include method part: " On the downside, it requires at least five times the size of the original data (” 0xNN,” for every original data-byte) "

Can anyone explain this? In the example he shows, the tool produces an array of 12 bytes, the exact same size as the input file.

1 comments
Perhaps he means encoding the data as ascii in the source is 5 times bigger than the original (i.e. 0xNN,), though I don't see why you have to write the data in the form 0xNN. Presumably you could just use a giant string, encoding non-ASCII characters.
You then need to escape characters that aren't legal in C string literals (such as double quotes, newlines and nul), and that's a lot more work than just converting the whole string. Also, string literals add a trailing nul byte, which is easy enough to deal with, but is also easy to forget about.
I'm lazy and typically just base64 it ;)