13
13

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.

ビット演算 (WIP)

Last updated at Posted at 2014-06-20

メモ中...

2 進数フラグ

a b c d e f g h
1 10 100 1000 10000 100000 1000000 10000000
1 2 4 8 16 32 64 128

例えば a, c, e のフラグが true である状態を表すと;

2 進数では;

10101 = 1 + 100 + 10000

10 進数では;

21 = 1 + 4 + 16

このように合計値からフラグの true 項目を知る事ができる。

10 進数から 2 進数を得る

function curry2 (func) {
  return function (arg2) {
    return function (arg1) {
      return func.call(arg1, arg2);
    }
  }
}
var parseDecimalToBinaryString = curry2(Number.prototype.toString)(2);
parseDecimalToBinaryString(7);

// => '111'

2 進数から 10 進数を得る

function curry2 (func) {
  return function (arg2) {
    return function (arg1) {
      return func(arg1, arg2);
    }
  }
}
var parseBinaryString = curry2(parseInt)(2);
parseBinaryString('111');

// => 7
13
13
1

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
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?