美文网首页
Hello Jianshu

Hello Jianshu

作者: less__is__more | 来源:发表于2019-02-14 11:00 被阅读0次

    print the binary data

    C++

    template <typename T>
    void printb(const T& t)
    {
        const size_t len = sizeof(T) * 8;
        char s[len + 1];
        typedef unsigned long long ull;
        auto buff = const_cast<ull&>(reinterpret_cast<const ull&>(t));
    
        s[len] = '\0';
        for (size_t i = len - 1; i != (size_t)-1; --i)
        {
            s[i] = buff & 1 ? '1' : '0';
            buff >>= 1;
        }
        
        cout << s;
    }
    

    相关文章

      网友评论

          本文标题:Hello Jianshu

          本文链接:https://www.haomeiwen.com/subject/xbiseqtx.html