Quantcast
Channel: George – UlduzSoft
Viewing all articles
Browse latest Browse all 55

Generating C or Java byte array from a binary using command-line tools

$
0
0

Once in a while during development a software engineer needs to embed the binary object as byte array in C or Java language. While coding a solution is simple, it could be achieved by the following command line on Linux or cygwin:

For unsigned data:

od -v -t u1 <binary file> | cut -c9- | sed 's/\([0-9]\+\)/\1,/g'

For signed data (Java byte arrays):

od -v -t d1 <binary file> | cut -c9- | sed 's/\([0-9]\+\)/\1,/g'

Viewing all articles
Browse latest Browse all 55

Trending Articles