7
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Node.js ファイルを読み込んで16進数で表示したい

Last updated at Posted at 2015-06-13

バイナリエディタで開いた感じっていうんですかね。あーゆーのを表示したい。

hoge.txt
hoge
loadfileAsHex.js

var fs=require("fs");

fs.readFile("hoge.txt",function(err,data){
    console.log(Buffer(data).toString("hex"));
});

結果686f6765

同期でやりたいならreadFileSyncを使って

var data= fs.readFileSync("hoge.txt");
console.log(Buffer(data).toString("hex");

ですね。

さらに、1E2Eみたいに大文字で表示させたいならtoUpperCaseを最後につけてあげればよいです。

toStringの引数でいろんな形式で表示できます。
以上。

7
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?