Skip to Content
Beginning C# 3.0
book

Beginning C# 3.0

by Jack Purdum
May 2008
Beginner
550 pages
13h 22m
English
Wrox
Content preview from Beginning C# 3.0

3.1. Integer Data Types

An integer data type is any numeric value expressed as a whole number. Integer values cannot have a fractional component associated with them. If you try to assign a fractional value to an integer variable, C# truncates the value. For example, if val is an integer data type, the statement

val = 6.9999;

assigns the value of 6 to val. This means that integer operations do not round values. If an integer data type has a fractional value, C# simply throws away the fractional component.

Table 3-1 lists the various integer data types that you can use in your programs.

Table 3-1. Table 3-1
Type SpecifierBitsRangeData Suffix
byte80 through 255 
sbyte8−128 through 127 
short16−32,768 through 32,767 
ushort160 through 65,535 
int32−2,147,483,648 through 2,147,483,647 
uint320 through 4,294,967,295U, u
long64−9,223,372,036,854,775,808 through 9,223,372,036,854,775,807L, l
ulong640 through 18,446,744,073,709,551,615UL, ul

3.1.1. Range of Integer Data Types

Each of the integer data types has a range of values that it can accommodate. Consider the byte data type, which uses eight bits. A binary digit, or bit, is the smallest unit of computer storage and may assume the value of on (1) or off (0). This means that the most basic unit of information in a computer — the bit — only has two possible states: on and off. Because there are only two possible states, information is stored in a computer in a binary, or base-two, format. While you and I perform mathematic operations using ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Navigating the Metaverse

Navigating the Metaverse

Cathy Hackl, Dirk Lueth, Tommaso Di Bartolo, John Arkontaky, Yat Siu
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
Capitalism at Risk

Capitalism at Risk

Joseph L. Bower, Herman B. Leonard, Lynn S. Paine

Publisher Resources

ISBN: 9780470261293Purchase book