Are binary protocols dead? [closed]

You Just Can’t Beat the Binary Binary protocols will always be more space efficient than text protocols. Even as internet speeds drastically increase, so does the amount and complexity of information we wish to convey. The text protocols you reference are outstanding in terms of standardization, flexibility and ease of use. However, there will always … Read more

Changing integer to binary string of digits

There are actually standard one-liners for these. #include <bitset> std::string s = std::bitset< 64 >( 12345 ).to_string(); // string conversion std::cout << std::bitset< 64 >( 54321 ) << ‘ ‘; // direct output std::bitset< 64 > input; std::cin >> input; unsigned long ul = input.to_ulong(); See this run as a demo.

Why does a byte only have 0 to 255?

Strictly speaking, the term “byte” can actually refer to a unit with other than 256 values. It’s just that that’s the almost universal size. From Wikipedia: Historically, a byte was the number of bits used to encode a single character of text in a computer and it is for this reason the basic addressable element … Read more

“grep” offset of ascii string from binary file

grep –byte-offset –only-matching –text foobar filename The –byte-offset option prints the offset of each matching line. The –only-matching option makes it print offset for each matching instance instead of each matching line. The –text option makes grep treat the binary file as a text file. You can shorten it to: grep -oba foobar filename It … Read more

How to modify bits in an integer?

These work for integers of any size, even greater than 32 bit: def set_bit(value, bit): return value | (1<<bit) def clear_bit(value, bit): return value & ~(1<<bit) If you like things short, you can just use: >>> val = 0b111 >>> val |= (1<<3) >>> ‘{:b}’.format(val) ‘1111’ >>> val &=~ (1<<1) ‘1101’

How to store a secret API key in an application’s binary?

There is no real perfect solution. No matter what you do, someone dedicated to it will be able to steal it. Even Twitter for iPhone/iPad/Android/mac/etc. has a secret key in there, they’ve likely just obscured it somehow. For example, you could break it up into different files or strings, etc. Note: Using a hex editor … Read more