Byte Data Type | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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!

5th Jul 2018, 6:31 AM
D Murry
D Murry - avatar
3 Answers
+ 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.
5th Jul 2018, 6:42 AM
Дмитро Іванов
Дмитро Іванов - avatar
0
First, try Console.Write(num + 1) Maybe the compiler is printing False as 0 represents False. That's what I think.
5th Jul 2018, 6:43 AM
Paul Grasser
Paul Grasser - avatar
0
Thank You... very clear and concise explanation
5th Jul 2018, 6:48 AM
D Murry
D Murry - avatar