Skip to content

Instantly share code, notes, and snippets.

@taniarascia
Last active February 13, 2024 07:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taniarascia/94b57541348555e91bcf0b5bd96e9e80 to your computer and use it in GitHub Desktop.
Save taniarascia/94b57541348555e91bcf0b5bd96e9e80 to your computer and use it in GitHub Desktop.
Read data
// echo -en "\x01\x02\x03hello" > data
// node read.js data
let fs = require('fs')
let file = process.argv.slice(2)[0]
let buffer = fs.readFileSync(file)
for (let value of buffer) {
let decimal = value
let hex = value.toString(16)
let ascii = String.fromCharCode(value)
console.log(`${decimal} 0x${hex} ${ascii}`)
}
/**
1 0x1
2 0x2
3 0x3
104 0x68 h
101 0x65 e
108 0x6c l
108 0x6c l
111 0x6f o
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment