// 10 進数
const state1 = 2;
// 2 進数で変換
const num = state1.toString(2);
// 文字列にして0埋めする
var ret = ( '000' + num ).slice( -3 );
console.log(ret); // "010"がかえる
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme