Skip to content

Instantly share code, notes, and snippets.

@DanielG
Created September 23, 2010 10:43
Show Gist options
  • Save DanielG/593458 to your computer and use it in GitHub Desktop.
Save DanielG/593458 to your computer and use it in GitHub Desktop.
#! /usr/bin/env node
// Very simple c/++ preprocessor for replacing binary(0b10101) with the hexer decimal representation
var fs = require('fs');
process.argv = process.argv.slice(2, process.argv.length);
console.log('Arguments:', process.argv);
process.argv.forEach(function(val, index, array){
if(val.match(/[a-zA-Z._-]*/)) {
process.nextTick(function (){
fs.readFile(val, function (err, data){
if (err) throw err;
var data = data.toString().replace(/0b([01]*)/g, function (match, capture){
var replace = parseInt(capture, 2).toString(16);
return '0x' + parseInt(capture, 2).toString(16);
});
console.log('New data:', data);
fs.writeFile(val, data, function(err){
if(err) throw err;
console.log('data written');
});
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment