⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apc.htm

📁 Why C++ is the emerging standard in software development. The steps to develop a C++ program. How
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><!-- This document was created from RTF source by rtftohtml version 3.0.1 -->	<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">	<TITLE>Teach Yourself C++ in 21 Days</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><H1></H1><H2 ALIGN="CENTER"><A HREF="apb.htm"><IMG SRC="../buttons/BLANPREV.GIF"WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><A HREF="http://www.mcp.com/sams"><IMGSRC="../buttons/BLANHOME.GIF" WIDTH="37" HEIGHT="37" ALIGN="BOTTOM"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../buttons/BLANTOC.GIF"WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><A HREF="apd.htm"><IMG SRC="../buttons/BLANNEXT.GIF"WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><BR><BR><BR><A NAME="Heading1"></A><FONT COLOR="#000077">Appendix C<BR><BR>Binary and Hexadecimal</FONT></H2><H2 ALIGN="CENTER"><FONT COLOR="#000077"></FONT></H2><P>You learned the fundamentals of arithmetic so long ago, it is hard to imaginewhat it would be like without that knowledge. When you look at the number 145 youinstantly see &quot;one hundred and forty-five&quot; without much reflection.</P><P>Understanding binary and hexadecimal requires that you re-examine the number 145and see it not as a number, but as a code for a number.</P><P>Start small: Examine the relationship between the number three and &quot;3.&quot;The numeral 3 is a squiggle on a piece of paper; the number three is an idea. Thenumeral is used to represent the number.</P><P>The distinction can be made clear by realizing that three, 3, |||, III, and ***all can be used to represent the same idea of three.</P><P>In base 10 (decimal) math you use the numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 torepresent all numbers. How is the number ten represented?</P><P>One can imagine that we would have evolved a strategy of using the letter A torepresent ten; or we might have used IIIIIIIIII to represent that idea. The Romansused X. The Arabic system, which we use, makes use of position in conjunction withnumerals to represent values. The first (right-most) column is used for &quot;ones,&quot;and the next column is used for tens. Thus, the number fifteen is represented as15 (read &quot;one, five&quot;); that is, 1 ten and 5 ones.</P><P>Certain rules emerge, from which some generalizations can be made:<DL>	<DD><B>1.</B> Base 10 uses the digits 0-9.<BR>	<BR>	<B>2.</B> The columns are powers of ten: 1s, 10s, 100s, and so on.<BR>	<B><BR>	3.</B> If the third column is 100, the largest number you can make with two columns	is 99. More generally, with n columns you can represent 0 to (10<SUP>n</SUP>-1).	Thus, with 3 columns you can represent 0 to (10<SUP>3</SUP>-1) or 0-999.</DL><H3 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">Other Bases</FONT></H3><P>It is not a coincidence that we use base 10; we have 10 fingers. One can imaginea different base, however. Using the rules found in base 10, you can describe base8:<DL>	<DD><B>1.</B> The digits used in base 8 are 0-7.<BR>	<B><BR>	2.</B> The columns are powers of 8: 1s, 8s, 64, and so on.<BR>	<B>3.</B> With n columns you can represent 0 to 8<SUP>n</SUP>-1.</DL><P>To distinguish numbers written in each base, write the base as a subscript nextto the number. The number fifteen in base 10 would be written as 15<SUB>10</SUB>and read as &quot;one, five, base ten.&quot;</P><P>Thus, to represent the number 15<SUB>10</SUB> in base 8 you would write 17<SUB>8</SUB>.This is read &quot;one, seven, base eight.&quot; Note that it can also be read &quot;fifteen&quot;as that is the number it continues to represent.</P><P>Why 17? The 1 means 1 eight, and the 7 means 7 ones. One eight plus seven onesequals fifteen. Consider fifteen asterisks:</P><PRE><FONT COLOR="#0066FF">*****     *****</FONT></PRE><PRE><FONT COLOR="#0066FF">*****</FONT></PRE><P>The natural tendency is to make two groups, a group of ten asterisks and anotherof five. This would be represented in decimal as 15 (1 ten and 5 ones). You can alsogroup the asterisks as</P><PRE><FONT COLOR="#0066FF">****          *******</FONT></PRE><PRE><FONT COLOR="#0066FF">****</FONT></PRE><P>That is, eight asterisks and seven. That would be represented in base eight as17<SUB>8</SUB>. That is, one eight and seven ones.<H3 ALIGN="CENTER"><A NAME="Heading4"></A><FONT COLOR="#000077">Around the Bases</FONT></H3><P>You can represent the number fifteen in base ten as 15, in base nine as 16<SUB>9</SUB>,in base 8 as 17<SUB>8</SUB>, in base 7 as 21<SUB>7</SUB>. Why 21<SUB>7</SUB>? Inbase 7 there is no numeral 8. In order to represent fifteen, you will need two sevensand one 1.</P><P>How do you generalize the process? To convert a base ten number to base 7, thinkabout the columns: in base 7 they are ones, sevens, forty-nines, three-hundred forty-threes,and so on. Why these columns? They represent 7<SUP>0</SUP>, 7<SUP>1</SUP>, 7<SUP>2</SUP>,7<SUP>4</SUP> and so forth. Create a table for yourself: <TABLE BORDER="0">	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">4</TD>		<TD ALIGN="LEFT">3</TD>		<TD ALIGN="LEFT">2</TD>		<TD ALIGN="LEFT">1</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">7<SUP>3</SUP></TD>		<TD ALIGN="LEFT">7<SUP>2</SUP></TD>		<TD ALIGN="LEFT">7<SUP>1</SUP></TD>		<TD ALIGN="LEFT">7<SUP>0</SUP></TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>343			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>49			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>7			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>1			</BLOCKQUOTE>			<P>		</TD>	</TR></TABLE>The first row represents the column number. The second row represents the power of7. The third row represents the decimal value of each number in that row.</P><P>To convert from a decimal value to base 7, here is the procedure: Examine thenumber and decide which column to use first. If the number is 200, for example, youknow that column 4 (343) is 0, and you don't have to worry about it.</P><P>To find out how many 49s there are, divide 200 by 49. The answer is 4, so put4 in column 3 and examine the remainder: 4. There are no 7s in 4, so put a zero inthe sevens column. There are 4 ones in 4, so put a 4 in the 1s column. The answeris 404<SUB>7</SUB>.</P><P>To convert the number 968 to base 6: <TABLE BORDER="0">	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">5</TD>		<TD ALIGN="LEFT">4</TD>		<TD ALIGN="LEFT">3</TD>		<TD ALIGN="LEFT">2</TD>		<TD ALIGN="LEFT">1</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">6<SUP>4</SUP></TD>		<TD ALIGN="LEFT">6<SUP>3</SUP></TD>		<TD ALIGN="LEFT">6<SUP>2</SUP></TD>		<TD ALIGN="LEFT">6<SUP>1</SUP></TD>		<TD ALIGN="LEFT">6<SUP>0</SUP></TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>1296			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>216			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>36			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>6			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>1			</BLOCKQUOTE>			<P>		</TD>	</TR></TABLE>There are no 1296s in 968, so column 5 has 0. Dividing 968 by 216 yields 4 with aremainder of 104. Column 4 is 4. Dividing 104 by 36 yields 2 with a remainder of32. Column 3 is 2. Dividing 32 by 6 yields 5 with a remainder of 2. The answer thereforeis 4252<SUB>6</SUB>. <TABLE BORDER="0">	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">5</TD>		<TD ALIGN="LEFT">4</TD>		<TD ALIGN="LEFT">3</TD>		<TD ALIGN="LEFT">2</TD>		<TD ALIGN="LEFT">1</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">6<SUP>4</SUP></TD>		<TD ALIGN="LEFT">6<SUP>3</SUP></TD>		<TD ALIGN="LEFT">6<SUP>2</SUP></TD>		<TD ALIGN="LEFT">6<SUP>1</SUP></TD>		<TD ALIGN="LEFT">6<SUP>0</SUP></TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">1296</TD>		<TD ALIGN="LEFT">216</TD>		<TD ALIGN="LEFT">36</TD>		<TD ALIGN="LEFT">6</TD>		<TD ALIGN="LEFT">1</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>0			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>4			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>2			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>5			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>2			</BLOCKQUOTE>			<P>		</TD>	</TR></TABLE>There is a shortcut when converting from one base to another base (such as 6) tobase 10. You can multiply: <TABLE BORDER="0">	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">4 * 216</TD>		<TD ALIGN="LEFT">=</TD>		<TD ALIGN="LEFT">864</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">2 * 36</TD>		<TD ALIGN="LEFT">=</TD>		<TD ALIGN="LEFT">72</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">5 * 6</TD>		<TD ALIGN="LEFT">=</TD>		<TD ALIGN="LEFT">30</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">2 * 1</TD>		<TD ALIGN="LEFT">=</TD>		<TD ALIGN="LEFT">2</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>968			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT"></TD>		<TD ALIGN="LEFT"></TD>	</TR></TABLE><CENTER><H4><A NAME="Heading5"></A><FONT COLOR="#000077">Binary</FONT></H4></CENTER><P>Base 2 is the ultimate extension of this idea. There are only two digits: 0 and1. The columns are: <TABLE BORDER="0">	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">Col:</TD>		<TD ALIGN="LEFT">8</TD>		<TD ALIGN="LEFT">7</TD>		<TD ALIGN="LEFT">6</TD>		<TD ALIGN="LEFT">5</TD>		<TD ALIGN="LEFT">4</TD>		<TD ALIGN="LEFT">3</TD>		<TD ALIGN="LEFT">2</TD>		<TD ALIGN="LEFT">1</TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">Power:</TD>		<TD ALIGN="LEFT">2<SUP>7</SUP></TD>		<TD ALIGN="LEFT">2<SUP>6</SUP></TD>		<TD ALIGN="LEFT">2<SUP>5</SUP></TD>		<TD ALIGN="LEFT">2<SUP>4</SUP></TD>		<TD ALIGN="LEFT">2<SUP>3</SUP></TD>		<TD ALIGN="LEFT">2<SUP>2</SUP></TD>		<TD ALIGN="LEFT">2<SUP>1</SUP></TD>		<TD ALIGN="LEFT">2<SUP>0</SUP></TD>	</TR>	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>Value:			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>128			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>64			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>32			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>16			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>8			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>4			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>2			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>1			</BLOCKQUOTE>			<P>		</TD>	</TR></TABLE>To convert the number 88 to base 2, you follow the same procedure: There are no 128s,so column 8 is 0.</P><P>There is one 64 in 88, so column 7 is 1 and 24 is the remainder. There are no32s in 24 so column 6 is 0.</P><P>There is one 16 in 24 so column 5 is 1. The remainder is 8. There is one 8 in8, and so column 4 is 1. There is no remainder, so the rest of the columns are 0.<TABLE BORDER="0">	<TR ALIGN="LEFT" rowspan="1">		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>0			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>1			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>0			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>1			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>1			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>0			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>0			</BLOCKQUOTE>			<P>		</TD>		<TD ALIGN="LEFT">			<BLOCKQUOTE>			<P>0			</BLOCKQUOTE>			<P>		</TD>	</TR></TABLE>To test this answer, convert it back:</P><PRE><FONT COLOR="#0066FF">1 * 64 =  640 * 32 =   01 * 16 =  161 *  8 =   80 *  4 =   00 *  2 =   00 *  1 =   0                88</FONT></PRE><CENTER><H4><A NAME="Heading6"></A><FONT COLOR="#000077">Why Base 2?</FONT></H4></CENTER><P>The power of base 2 is that it corresponds so cleanly to what a computer needsto represent. Computers do not really know anything at all about letters, numerals,instructions, or programs. At their core they are just circuitry, and at a givenjuncture there either is a lot of power or there is very little.</P><P>To keep the logic clean, engineers do not treat this as a relative scale (a littlepower, some power, more power, lots of power, tons of power), but rather as a binaryscale (&quot;enough power&quot; or &quot;not enough power&quot;). Rather than saying&quot;enough&quot; or &quot;not enough,&quot; they simplify it to &quot;yes&quot;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -