Giter VIP home page Giter VIP logo

extractbits's Introduction

extractbits

extract bits field with given bit offset from raw bytes

ex)


         bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
byte 0  |      Header       |  length |  field1 |
        -----------------------------------------
byte 1  |  field2                          | f3 |
        -----------------------------------------
byte 2  |         f3             |  field4      |
        -----------------------------------------
byte 3  |               field4                  |
        -----------------------------------------
byte 4  | field4   |       field5               |
        -----------------------------------------

    Header = extractByte(data, 0, 7, 4); // byteOffset 0, bitOffset 7, bitLength=4
    length = extractByte(data, 0, 3, 2);
    field1 = extractByte(data, 0, 1, 2);
    field2 = extractByte(data, 1, 7, 6);
    f3 = extractByte(data, 1, 0, 6);
    field4 = extractWord(data, 2, 2, 12);
    field5 = extractWord(data, 4, 5, 6);
    // dest will store data as LSByte order. 
    // byte 0 : byte 4(bit 6, 7) and byte 3(bit 5 4 3 2 1 0), 
    // byte 1 : byte 3(bit 7, 6) and byte 2(bit 2 1 0)
    uint8_t dest[100];
    field4lsb = extractBits(data, 2, 2, 12, dest);

extractbits's People

Contributors

yjinnlee avatar

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.