0
Byte Data Type
Anyone mind explaining the "byte" data type? I'm familiar with the usual int,float,etc., but not byte. byte num = 255; Console.Write(num += 1); The output of this is 0 but I'm not sure why? Any insight would be appreciated. Thank You!
3 Réponses
+ 2
Byte data type is actually a byte: eight bits. And bit is one binary unit, which can have value 0 or 1. So byte has 8 such units and maximum value a byte can store is 11111111. 11111111 in binary is 255 in decimal. When you add 1 to 255 you get 256, that is 100000000 in binary. But byte type can store only 8 bits, so the ninth senior bit is lost and we get 00000000, which is, of course, zero.
0
First, try Console.Write(num + 1)
Maybe the compiler is printing False as 0 represents False. That's what I think.
0
Thank You... very clear and concise explanation