Bits length

    0

    0

    Giovanny Gongora

    Codiga's C++ Recipes

    Get the length of bits of a variable

    #include <iostream>
    
    unsigned bits, var = (x < 0) ? -x : x;
    for(bits = 0; var != 0; ++bits) var >>= 1;
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.