- 1
Pls help me how to get the right value of bit in c # program
3 Answers
+ 1
What do you mean by "right value of bit"?
+ 1
The number 21 in my program should be 8 in output
+ 1
Use sizeof operator to get size of a certain type (in bytes), and then multiply it by 8 (the number of bits per byte) to get the number of bits for the respective data type.
Console.WriteLine( sizeof( int ) ); // in bytes
Console.WriteLine( sizeof( int ) * 8 ); // in bits
Reference:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/sizeof