How to visualize bytes with C/C++

后端 未结 7 708
小蘑菇
小蘑菇 2020-12-15 10:16

I\'m working my way through some C++ training. So far so good, but I need some help reinforcing some of the concepts I am learning. My question is how do I go about visualiz

7条回答
  •  借酒劲吻你
    2020-12-15 10:51

    A little bit by bit console program i whipped up, hope it helps somebody

    #include 
    #include 
    #include 
    using namespace std;
    typedef  vector ByteVector;
    ///////////////////////////////////////////////////////////////
    uint8_t Flags[8] = { 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
    void print_bytes(ByteVector Bv){
        for (unsigned i = 0; i < Bv.size(); i++){
            printf("Byte %d [ ",i);
            for (int j  = 0;j < 8;++j){
                Bv[i] & Flags[j] ? printf("1") : printf("0");
            }
            printf("]\n");
        }
    }
    int main(){
        ByteVector Bv;
        for (int i = 0; i < 4; ++i) { Bv.push_back(i); }
        print_bytes(Bv);
    }
    

提交回复
热议问题