1
1

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 1 year has passed since last update.

10進数を2進数に変更して指定の桁数で0埋めにする処理

Posted at
// 10 進数
const state1 = 2;

// 2 進数で変換
const num = state1.toString(2);

// 文字列にして0埋めする
var ret = ( '000' + num ).slice( -3 );

console.log(ret); // "010"がかえる
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?