O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.4. Unsigned types in C#

Unsigned types are types which cannot store values in the negative range (hence unsigned – the values stored are always positive). [4] The unsigned integral types in C# are: byte (not ubyte!), ushort, uint, and ulong. [5]

[4] The reason for unsigned types is that you can store twice as many values in the positive range with the same number of bits because one bit is no longer required for storing the sign. Signed types always 'waste' one bit for determining if the value stored is positive or negative. There is no way in Java we can 'save' on the wasted bit, even if we know for certain that a particular value can never be negative. Anyway, this is probably not a significant issue given the amount of memory available to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required