Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

ビット演算 (WIP)

More than 5 years have passed since last update.

メモ中...

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
japboy
無気力。
ikyu
「こころに贅沢を」をコンセプトに一休.com、一休レストランなどのサービスを提供しています。
https://www.ikyu.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away