how to find no of bits

how to find no of bits taken by integer
e.g no of bits of 42 is 6
If I'm reading your question correctly I believe you use the standard library's sizeof() function to discover how much memory (in bytes) an object (of some arbitrary data type) takes up. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main()
{
    int james = 4568;
    int jesse = 6;

    std::cout << sizeof(james)<<'\n';
    std::cout << sizeof(jesse)<<'\n';
    std::cout << sizeof(int)<<'\n';

    return 0;
}



All three sizeof() statements should return 4.
Hope I helped. If I didn't, please elaborate.

Edited my initial pseudocode.
Last edited on
Topic archived. No new replies allowed.