What is the difference between a word short
and ushort
in C#? They are both 16 bits!
What is the difference between a short and ushort in C#?
24.4k Views Asked by Adam At
2
There are 2 best solutions below
0

A (machine) word is the native size of the processor registers. It's generally what C has used as size for the int
data type. In C# the data types has a fixed size and does not depend on the processor architecture.
In Intel assembly language the WORD
data type has come to mean 16 bits, a DWORD
(double word) is 32 bits and a QWORD
(quad word) is 64 bits. The WORD
type is also used in the Windows API with the same meaning.
So, the WORD
data type corresponds to the C# type ushort
.
C# does not have a
word
type. If you meanshort
orInt16
, the difference is thatushort
is unsigned.short
can be any value from-32768
to32767
, whereasushort
can be from0
to65535
. They have the same total range and use the same number of bits but are interpreted in different ways, and have different maximums/minimums.Clarification: A word is a general computer science term that is typically used to refer to the largest single group of bits that can be handled by the CPU in a single operation. So if your CPU (and operating system) are 32-bit, then a word is an
Int32
orUInt32
(C#:int
/uint
). If you're on a 64-bit CPU/OS, a word is actually anInt64/UInt64
(C#:long
/ulong
). The term "word" usually refers only to the bit size of a variable as opposed to how it is actually interpreted in a program.