Pls help me how to get the right value of bit in c # program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Pls help me how to get the right value of bit in c # program

https://code.sololearn.com/chPW6R1eXlaY/?ref=app

26th Jan 2021, 6:17 AM
Chararaat
Chararaat - avatar
3 Answers
+ 1
What do you mean by "right value of bit"?
26th Jan 2021, 8:38 AM
Ipang
+ 1
The number 21 in my program should be 8 in output
26th Jan 2021, 3:27 PM
Chararaat
Chararaat - avatar
+ 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
26th Jan 2021, 8:53 PM
Ipang