<?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>C ++ &#187; 65535</title>
	<atom:link href="http://www.bizzymicbizness.com/cplusplus/tag/65535/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bizzymicbizness.com/cplusplus</link>
	<description>All about C++</description>
	<lastBuildDate>Mon, 19 Oct 2009 12:38:17 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unsigned Types</title>
		<link>http://www.bizzymicbizness.com/cplusplus/unsigned-types</link>
		<comments>http://www.bizzymicbizness.com/cplusplus/unsigned-types#comments</comments>
		<pubDate>Tue, 15 Sep 2009 07:07:32 +0000</pubDate>
		<dc:creator>BMB</dc:creator>
				<category><![CDATA[C++ Glossary]]></category>
		<category><![CDATA[#include]]></category>
		<category><![CDATA[-32768]]></category>
		<category><![CDATA[32767]]></category>
		<category><![CDATA[64 bits]]></category>
		<category><![CDATA[65535]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[long long]]></category>
		<category><![CDATA[unsigned int]]></category>
		<category><![CDATA[unsigned long]]></category>
		<category><![CDATA[unsigned long long]]></category>
		<category><![CDATA[unsigned short]]></category>
		<category><![CDATA[Unsigned Types]]></category>

		<guid isPermaLink="false">http://www.bizzymicbizness.com/cplusplus/?p=370</guid>
		<description><![CDATA[You should use unsigned types

Only for quantities that are never negative (B-1)

(B-1) Such as populations and bean counts




To create unsigned versions of the basic integer types

You just use the keyword unsigned to modify the declarations (A-1):


Example of (A-1)

unsigned short change;		// unsigned short type
unsigned int univac; 		// unsigned int type
unsigned eniac;			// also unsigned int
unsigned long edvac;		// [...]]]></description>
			<content:encoded><![CDATA[<p>You should use unsigned types</p>
<ul>
<li>Only for quantities that are never negative (B-1)
<ul>
<li>(B-1) Such as populations and bean counts</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
To create unsigned versions of the basic integer types</p>
<ul>
<li>You just use the keyword unsigned to modify the declarations (A-1):</li>
</ul>
<p><br class="blank" /><br />
Example of (A-1)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">short</span> change<span style="color: #008080;">;</span>		<span style="color: #666666;">// unsigned short type</span>
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> univac<span style="color: #008080;">;</span> 		<span style="color: #666666;">// unsigned int type</span>
<span style="color: #0000ff;">unsigned</span> eniac<span style="color: #008080;">;</span>			<span style="color: #666666;">// also unsigned int</span>
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span> edvac<span style="color: #008080;">;</span>		<span style="color: #666666;">// unsigned long type</span></pre></div></div>

<p><br class="blank" /><br />
Note that <strong>unsigned</strong> by itself</p>
<ul>
<li>Is short for <strong>unsigned int</strong></li>
</ul>
<p><br class="blank" /><br />
(A-2) illustrates the use of unsigned types</p>
<ul>
<li>It also shows you what happen if your program tries to go beyond the limits for integer types (B-2)</li>
<li>(B-2) Finally, it gives you one last look at the preprocessor <strong># define</strong> statement</li>
</ul>
<p><br class="blank" /><br />
Example of (A-2)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#define ZERO 0	// makes ZERO symbol for 0 value</span>
<span style="color: #339900;">#include &lt;climits&gt;	// defines INT_MAX as largest int value</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">short</span> johnPresperEckert <span style="color: #000080;">=</span> <span style="color: #0000ff;">SHRT_MAX</span><span style="color: #008080;">;</span>			<span style="color: #666666;">// initialize a variable to max value</span>
	<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">short</span> johnWilliamMauchly <span style="color: #000080;">=</span> johnPresperEckert<span style="color: #008080;">;</span>	<span style="color: #666666;">// okay if variable johnPresperEckert already defined</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Eckert has &quot;</span> <span style="color: #000080;">&lt;&lt;</span> johnPresperEckert <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; dollars and Mauchly has &quot;</span> <span style="color: #000080;">&lt;&lt;</span> johnWilliamMauchly<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; dollars deposited.&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl
		 <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; Add $1 to each account. &quot;</span><span style="color: #000080;">&lt;&lt;</span> endl <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Now &quot;</span><span style="color: #008080;">;</span>
	johnPresperEckert <span style="color: #000080;">=</span> johnPresperEckert <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
	johnWilliamMauchly <span style="color: #000080;">=</span> johnWilliamMauchly <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Eckert has &quot;</span> <span style="color: #000080;">&lt;&lt;</span> johnPresperEckert <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; dollars and Mauchly has &quot;</span> <span style="color: #000080;">&lt;&lt;</span> johnWilliamMauchly<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; dollars deposited.<span style="color: #000099; font-weight: bold;">\n</span>Poor Eckert.&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	johnPresperEckert <span style="color: #000080;">=</span> ZERO<span style="color: #008080;">;</span>
	johnWilliamMauchly <span style="color: #000080;">=</span> ZERO<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Eckert has &quot;</span> <span style="color: #000080;">&lt;&lt;</span> johnPresperEckert <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; dollars and Mauchly has &quot;</span> <span style="color: #000080;">&lt;&lt;</span> johnWilliamMauchly<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; dollars deposited.&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl
		 <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; Take $1 from each account. &quot;</span><span style="color: #000080;">&lt;&lt;</span> endl <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Now &quot;</span><span style="color: #008080;">;</span>
	johnPresperEckert <span style="color: #000080;">=</span> johnPresperEckert <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
	johnWilliamMauchly <span style="color: #000080;">=</span> johnWilliamMauchly <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Eckert has &quot;</span> <span style="color: #000080;">&lt;&lt;</span> johnPresperEckert <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; dollars and Mauchly has &quot;</span> <span style="color: #000080;">&lt;&lt;</span> johnWilliamMauchly<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; dollars deposited.&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Lucky Mauchly&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><br class="blank" /><br />
Compatibility Note</p>
<ul>
<li>The example (A-2), uses the <strong>climits</strong> file; older compilers might need to use <strong>limits.h</strong>, and some very old compilers might not have either file available</li>
</ul>
<p><br class="blank" /><br />
Here’s the output from the program in (A-2):</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-387" title="Output" src="http://www.bizzymicbizness.com/cplusplus/wp-content/uploads/2009/09/Output.jpg" alt="Output" width="536" height="260" /></p>
<p><br class="blank" /><br />
The program</p>
<ul>
<li>Sets a short variable (<strong>johnPresperEckert</strong>) and an unsigned short variable (<strong>johnWilliamMauchly</strong>) to the largest <strong>short</strong> value, which is 32,767 on our system (B-3)</li>
<li>(B-3) Then it adds 1 to each value (B-4)</li>
<li>(B-4) This causes no problems for <strong>johnWilliamMauchly</strong> because the new value is still much less than the maximum value for an unsigned integer (B-5)</li>
<li>(B-5) But <strong>johnPresperEckert </strong>goes from 32,767 to -32,768 (B-6)</li>
<li>(B-6) Similarly, subtracting 1 from 1 from 0 creates no problems for <strong>johnPresperEckert</strong>, but it makes the unsigned variable <strong>johnWilliamMauchly</strong> go from 0 to 65,535 (B-7)</li>
<li>(B-7) As you can see, these integers behave much like an odometers (B-8)</li>
<li>(B-8) If you go past the limit, the values just start over at the other end of the range
<ul>
<li>(Image-1) C++ guarantees that unsigned types behave in this fashion</li>
<li>However, C++ doesn’t guarantee that signed integer types can exceed their limits (overflow and underflow) without complaint, but that is the most common behavior on current implementations</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
(Image-1) Typical overflow behavior for integers</p>
<p style="text-align: center;"> <img class="aligncenter size-full wp-image-371" title="Typical overflow behavior for signed integer" src="http://www.bizzymicbizness.com/cplusplus/wp-content/uploads/2009/09/Typical-overflow-behavior-for-signed-integer.jpg" alt="Typical overflow behavior for signed integer" width="569" height="466" /></p>
<p><br class="blank" /><br />
<br class="blank" /></p>
<p style="text-align: center;"> <img class="aligncenter size-full wp-image-372" title="Typical overflow behavior for unsigned integer" src="http://www.bizzymicbizness.com/cplusplus/wp-content/uploads/2009/09/Typical-overflow-behavior-for-unsigned-integer.jpg" alt="Typical overflow behavior for unsigned integer" width="569" height="466" /></p>
<p><br class="blank" /><br />
Beyond long</p>
<ul>
<li>C99 has added a couple new types that most likely will be part of the next edition of the C++ Standard (B-9)
<ul>
<li>Indeed, many C++ compilers already support them</li>
<li>(B-9) The types are<strong> long long</strong> and <strong>unsigned</strong> <strong>long long</strong>. Both are guaranteed to be at least 64 bits and to be at least as wide as the <strong>long</strong> and <strong>unsigned long</strong> types</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bizzymicbizness.com/cplusplus/unsigned-types/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Short Integers</title>
		<link>http://www.bizzymicbizness.com/cplusplus/short-integers</link>
		<comments>http://www.bizzymicbizness.com/cplusplus/short-integers#comments</comments>
		<pubDate>Mon, 07 Sep 2009 12:18:38 +0000</pubDate>
		<dc:creator>BMB</dc:creator>
				<category><![CDATA[Variable and Data Types]]></category>
		<category><![CDATA[65535]]></category>
		<category><![CDATA[Byte]]></category>
		<category><![CDATA[short]]></category>
		<category><![CDATA[Short Integers]]></category>

		<guid isPermaLink="false">http://www.bizzymicbizness.com/cplusplus/?p=290</guid>
		<description><![CDATA[A word

Which is a group of 16 contiguous bits or 2 bytes, is used to represent a natural number
As we have studied, the maximum numeric value that can fit in a word is 65535
Since the Byte is used only to represent a character, whenever you plan to use a number in your program, the minimum [...]]]></description>
			<content:encoded><![CDATA[<p>A word</p>
<ul>
<li>Which is a group of 16 contiguous bits or 2 bytes, is used to represent a natural number</li>
<li>As we have studied, the maximum numeric value that can fit in a word is 65535</li>
<li>Since the Byte is used only to represent a character, whenever you plan to use a number in your program, the minimum representation you should/must use is a word</li>
</ul>
<p><br class="blank" /><br />
An algebraic natural number</p>
<ul>
<li>Is also called an integer</li>
</ul>
<p><br class="blank" /><br />
The smallest integer you can store in a word</p>
<ul>
<li>Is declared with the <strong>short</strong> keyword followed by a name</li>
</ul>
<p><br class="blank" /><br />
A <strong>short</strong> integer is <strong>signed</strong> by default</p>
<ul>
<li>It can store a value that ranges from –32768 to 32767</li>
<li>Here is an example program that uses two <strong>short</strong> integers (A-1):</li>
</ul>
<p><br class="blank" /><br />
Example of (A-1)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0000ff;">short</span> number1, number2<span style="color: #008080;">;</span>
&nbsp;
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Enter a number between -32768 and 32767: &quot;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cin</span> <span style="color: #000080;">&gt;&gt;</span> number1<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Enter another number: &quot;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cin</span> <span style="color: #000080;">&gt;&gt;</span> number2<span style="color: #008080;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>The numbers you entered were<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>Number 1: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> number1 <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>Number 2: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> number2 <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><br class="blank" /> <br />
By default, a <strong>short</strong> integer</p>
<ul>
<li>Is <strong>signed</strong></li>
<li>You can also explicitly declare such a variable as a <strong>signed short</strong></li>
<li>Here is an example (A-2):</li>
</ul>
<p><br class="blank" /> <br />
Example of (A-2)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">signed</span> <span style="color: #0000ff;">short</span> XCoord<span style="color: #008080;">;</span></pre></div></div>

<p><br class="blank" /><br />
If the integer must be positive</p>
<ul>
<li>You should declared as an <strong>unsigned short</strong></li>
</ul>
<p><br class="blank" /><br />
The <strong>unsigned short</strong> is used</p>
<ul>
<li>To identify a 16-bit positive integer whose value would range from 0 to 65535</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bizzymicbizness.com/cplusplus/short-integers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

