How to compile a linux shell script to be a standalone executable *binary* (i.e. not just e.g. chmod 755)?

The solution that fully meets my needs would be SHC – a free tool, or CCsh a commercial tool. Both compile shell scripts to C, which then can be compiled using a C compiler. Links about SHC: https://github.com/neurobin/shc http://www.datsi.fi.upm.es/~frosal/ http://www.downloadplex.com/Linux/System-Utilities/Shell-Tools/Download-shc_70414.html Links about CCsh: http://www.comeaucomputing.com/faqs/ccshlit.html

Two’s Complement Binary in Python?

It works best if you provide a mask. That way you specify how far to sign extend. >>> bin(-27 & 0b1111111111111111) ‘0b1111111111100101’ Or perhaps more generally: def bindigits(n, bits): s = bin(n & int(“1″*bits, 2))[2:] return (“{0:0>%s}” % (bits)).format(s) >>> print bindigits(-31337, 24) 111111111000010110010111 In basic theory, the actual width of the number is a …

Read more

Getting binary content in node.js with http.request

The accepted answer did not work for me (i.e., setting encoding to binary), even the user who asked the question mentioned it did not work. Here’s what worked for me, taken from: http://chad.pantherdev.com/node-js-binary-http-streams/ http.get(url.parse(‘http://myserver.com:9999/package’), function(res) { var data = []; res.on(‘data’, function(chunk) { data.push(chunk); }).on(‘end’, function() { //at this point data is an array of …

Read more

How to reverse an std::string? [duplicate]

I’m not sure what you mean by a string that contains binary numbers. But for reversing a string (or any STL-compatible container), you can use std::reverse(). std::reverse() operates in place, so you may want to make a copy of the string first: #include <algorithm> #include <iostream> #include <string> int main() { std::string foo(“foo”); std::string copy(foo); …

Read more

Generate all binary strings of length n with k bits set

This method will generate all integers with exactly N ‘1’ bits. From https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation Compute the lexicographically next bit permutation Suppose we have a pattern of N bits set to 1 in an integer and we want the next permutation of N 1 bits in a lexicographical sense. For example, if N is 3 and the …

Read more

Convert string to binary then back again using PHP

You want to use pack and base_convert. // Convert a string into binary // Should output: 0101001101110100011000010110001101101011 $value = unpack(‘H*’, “Stack”); echo base_convert($value[1], 16, 2); // Convert binary into a string // Should output: Stack echo pack(‘H*’, base_convert(‘0101001101110100011000010110001101101011’, 2, 16));