<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bitmatic &#187; types</title>
	<atom:link href="http://bitmatic.com/tag/types/feed" rel="self" type="application/rss+xml" />
	<link>http://bitmatic.com</link>
	<description>Lean IT-solutions in .NET/C#</description>
	<lastBuildDate>Tue, 11 Jan 2011 09:37:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Integer types and their ranges</title>
		<link>http://bitmatic.com/c/integer-types-and-their-ranges</link>
		<comments>http://bitmatic.com/c/integer-types-and-their-ranges#comments</comments>
		<pubDate>Thu, 05 Mar 2009 12:52:38 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[types]]></category>

		<guid isPermaLink="false">http://bitmatic.com/?p=226</guid>
		<description><![CDATA[There are 8 basic integer types in C#. The names and ranges af these types are an industry standard, so they should also be valid in most other languages.
This article describes the range of values these types can hold, as well as a few usefull tricks.]]></description>
			<content:encoded><![CDATA[<p>There are 8 basic integer types in C#. The names and ranges af these types are an industry standard, so they should also be valid in most other languages.</p>
<table width="100%" margin="0" padding="5" cellspacing="0">
<tr style="font-weight:bold;">
<td>Keyword</td>
<td colspan="3"><center>Range</center></td>
<td style="text-align:right;">bits</td>
</tr>
<tr <?php $i=0; if($i++%2 == 0) echo 'style="background:#F0F0FF;"' ?>></p>
<td>byte</td>
<td style="text-align:right;">0</td>
<td style="text-align:center;padding:4px 10px 4px 10px;">to</td>
<td>255</td>
<td style="text-align:right;">8</td>
</tr>
<tr <?php if($i++%2 == 0) echo 'style="background:#F0F0FF;"' ?>></p>
<td>sbyte</td>
<td style="text-align:right;">-128</td>
<td style="text-align:center;padding:4px 10px 4px 10px;">to</td>
<td>127</td>
<td style="text-align:right;">8</td>
</tr>
<tr <?php if($i++%2 == 0) echo 'style="background:#F0F0FF;"' ?>></p>
<td>ushort</td>
<td style="text-align:right;">0</td>
<td style="text-align:center;padding:4px 10px 4px 10px;">to</td>
<td>65536</td>
<td style="text-align:right;">16</td>
</tr>
<tr <?php if($i++%2 == 0) echo 'style="background:#F0F0FF;"' ?>></p>
<td>short</td>
<td style="text-align:right;">-32768</td>
<td style="text-align:center;padding:4px 10px 4px 10px;">to</td>
<td>32767</td>
<td style="text-align:right;">16</td>
</tr>
<tr <?php if($i++%2 == 0) echo 'style="background:#F0F0FF;"' ?>></p>
<td>int</td>
<td style="text-align:right;">-2,147,483,648</td>
<td style="text-align:center;padding:4px 10px 4px 10px;">to</td>
<td>2,147,483,647</td>
<td style="text-align:right;">32</td>
</tr>
<tr <?php if($i++%2 == 0) echo 'style="background:#F0F0FF;"' ?>></p>
<td>uint</td>
<td style="text-align:right;">0</td>
<td style="text-align:center;padding:4px 10px 4px 10px;">to</td>
<td>4,294,967,295</td>
<td style="text-align:right;">32</td>
</tr>
<tr <?php if($i++%2 == 0) echo 'style="background:#F0F0FF;"' ?>></p>
<td>long</td>
<td style="text-align:right;">-9,223,372,036,854,775,808</td>
<td style="text-align:center;padding:4px 10px 4px 10px;">to</td>
<td>9,223,372,036,854,775,807</td>
<td style="text-align:right;">64</td>
</tr>
<tr <?php if($i++%2 == 0) echo 'style="background:#F0F0FF;"' ?>></p>
<td>ulong</td>
<td style="text-align:right;">0</td>
<td style="text-align:center;padding:4px 10px 4px 10px;">to</td>
<td>18,446,744,073,709,551,615</td>
<td style="text-align:right;">64</td>
</tr>
</table>
<p>On first glance you may find these numbers odd, but this is due to the fact that computers represent these numbers using binary and hexadecimal numbers. In these number systems they are nice round numbers.</p>
<h3>Signed/Unsigned</h3>
<p>All the integer types come in pairs. One signed and one unsigned. All the unsigned types go from 0 to 2^x &#8211; 1, where x is the number of bits in the type (the &#8220;width&#8221; of the type).<br />
The signed types have one more negative number than positive ones. This may seem strange, but this is basically (slightly simplified) because zero is treated as a positive number, and so it all adds up in the end&#8230;</p>
<h3>Quick and dirty range check</h3>
<p>There is a very simple way of telling an approximate range of any integer. It just so happens that 2^10 is almost exactly 1000. 1024 to be exact.<br />
This means that for every 10 bits in an integer, you can multiply the range by 1000. So 20 bits for instance would give an approximate range of 1000*1000, or 1,000,000, and 32 bits would give 1000*1000*1000*4 (the 4 is for the last 2 bits&#8230;) or 4,000,000,000.<br />
As you can see in the table above, it is only an approximation since the exact number is 4,294,967,295, but for most purposes it is good enough.</p>
]]></content:encoded>
			<wfw:commentRss>http://bitmatic.com/c/integer-types-and-their-ranges/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

