Giter Site home page Giter Site logo

bitoperation's Introduction

bits operating classes
written by MATSUMOTO Eiji
from March 2, 2010

0. Basis

    include file : Bits.h
    namespace    : emattsan::bits

1. Integer types of specified number of bits

    Bits<4, signed> s; // signed 4 bit integer (-8..7)
    Bits<4>         u; // (or Bits<4, unsigned>) unsigned 4 bit integer (0..15)

    s = 7;  // s => 7
    s = 8;  // s => -8
    s = 15; // s => -1
    s = 16; // s => 0

    u = 7;  // u => 7
    u = 8;  // u => 8
    u = 15; // u => 15
    u = 16; // u => 0

2. Join

    Bits<4, signed> s(1); // s => 1 ( 0001b )
    BIts<4>         u(8); // u => 8 ( 1000b )

    int n = (s, u); // n => 24 ( 18h / 00011000b )

    int n = (s, s, s); // n => 265 ( 111h / 000100010001b )

    (s, n) = 0x5a; // s => 5, n = 10 ( 0ah )

3. Reserved bits

    Bits<4, signed> s(1); // s => 1 ( 0001b )
    Bits<4>         u(8); // u => 8 ( 1000b )

    int n = (s, reserve<2>, u); // n => 72 ( 048h / 0001001000b )

    (s, reserve<2>, u) = 0xff; // s => 3 ( 0011b), (2 reserved bits discarded), u => 15 ( 1111b ), 


<<EOF>>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.