{"id":34,"date":"2019-08-12T09:44:29","date_gmt":"2019-08-12T08:44:29","guid":{"rendered":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/?post_type=chapter&#038;p=34"},"modified":"2019-12-31T10:02:27","modified_gmt":"2019-12-31T10:02:27","slug":"numbers-in-computing","status":"publish","type":"chapter","link":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/chapter\/numbers-in-computing\/","title":{"raw":"Numbers in Computing","rendered":"Numbers in Computing"},"content":{"raw":"<blockquote>\r\n<p style=\"text-align: right;\"><em>Mathematics is the most beautiful and most<\/em>\r\n<em>powerful creation of the human spirit.<\/em><\/p>\r\n<p style=\"text-align: right;\">Stefan Banach<\/p>\r\n<\/blockquote>\r\nComputer processors might be perceived as extremely efficient \u201cnumber crunchers\u201d which means that they process enormous streams of information expressed only with numbers. It is worth for engineers to understand various ways by which electronic systems process these numbers.\r\n\r\nHumans in almost every corner of the earth are used to decimal system. This is so easy and natural to count with fingers hence positional system based on powers of tens is the most common nowadays. It is well known in practice but revising it might be helpful in understanding other systems discussed here. Look at the example:\r\n\r\n<span class=\"math display\">$latex 40375 = 4\\times10^4 + 0\\times10^3 + 3\\times10^2 + 7\\times10^1 + 5\\times10^0 = 40000 + 0 + 300 + 70 + 5 $<\/span>\r\n\r\nIn computer systems decimal numbers usually have no prefix or suffix but sometimes they are suffixed with \u201cd\u201d: <span class=\"math inline\">$latex 40375d $<\/span>.\r\n<h2 id=\"section:binary\">Binary System<\/h2>\r\nComputers do not use decimal system. They are working on <em>bits<\/em> where bit is unit of information. It can have only one of two possible but different values such as:\r\n<table style=\"width: 617px; height: 45px;\">\r\n<thead>\r\n<tr class=\"header\" style=\"height: 15px;\">\r\n<th style=\"text-align: center; width: 359.773px; height: 15px;\">True<\/th>\r\n<th style=\"text-align: center; width: 258.864px; height: 15px;\">False<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\" style=\"height: 15px;\">\r\n<td style=\"text-align: center; width: 359.773px; height: 15px;\">1<\/td>\r\n<td style=\"text-align: center; width: 259.773px; height: 15px;\">0<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 15px;\">\r\n<td style=\"text-align: center; width: 359.773px; height: 15px;\">Day<\/td>\r\n<td style=\"text-align: center; width: 259.773px; height: 15px;\">Night<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\nBinary system has only two digits: 0 and 1. It is also positional as decimal system, but the base equals 2 (that is number of digits). Binary numers sometimes are suffixed with letter \u201cb\u201d or prefixed with \u201c0b\u201d. In the following example every multiplicand is expressed in decimal mode but it was omitted to simplify the equation and make it easier to follow the process:\r\n\r\n<span class=\"math display\">$latex 0b1011 = 1\\times2^3 + 0\\times2^2 + 1\\times2^1 + 1\\times2^0 = 1\\times8 + 0\\times4 + 1\\times2 + 1\\times1 = 8d + 2d + 1d = 11d $<\/span>\r\n\r\nAbove example also shows how binary number is converted to decimal mode. The series of multiplicands (starting from the rightmost position) in this conversion is easy to understand, reproduce or even remember: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8129, 16384, 32768, 65536, \u2026\r\n\r\nConversion in from decimal mode to binary is a bit more tricky and there are several ways to do it. First approach is repetitive division by 2 with remainder that indicates value of bit at specific position. Example:\r\n\r\n<span class=\"math display\">$latex \\begin{aligned}\r\n11d = 2\\times5d + 1\\\\\r\n5d = 2\\times2d + 1\\\\\r\n2d = 2\\times1d + 0\\\\\r\n1d = 2\\times0d + 1\\end{aligned} $<\/span>\r\n\r\nIf we write remainders starting from the last one we will get binary value: <strong>1011<\/strong>b.\r\n\r\nThe above method works well for any value. But for small values simpler method might be employed which is based on subtraction. However, it requires to know (e.g. remember) weights at different digit positions. In every step a biggest possible weight is subtracted from the number that is being converted provided that result will remain positive number. At positions with corresponding weights \u201cones\u201d are set leaving all other positions with \u201czeros\u201d. Example:\r\n\r\n<span class=\"math display\">$latex \\begin{aligned}\r\n11d - 8d &amp;= 3d \\qquad\\text{8d subtracted successfully so there should be ``1''}\\\\\r\n3d - 0d &amp;= 3d \\qquad\\text{4d cannot be subtracted within positive integers so ``0''}\\\\\r\n3d - 2d &amp;= 1d \\qquad\\text{2d subtracted successfully so there should be ``1''}\\\\\r\n1d - 1d &amp;= 0d \\qquad\\text{1d left so there should be ``1'' in the last position}\\end{aligned} $<\/span>\r\n\r\nThis method may be much faster than previous one for small numbers. There is no threshold given how \u201csmall\u201d the number should be as it depends on experience of the person that is doing the conversion. Range of one nibble (4 bits) is easy to achieve while full byte (8 bits) is little harder, although even 12-bit values are possible to be converted by human being without neither calculator or pen and paper at hand.\r\n\r\nBinary system is foundation for boolean algebra. In typical computer implementations there are usually four basic operations available as presented in the table [1.1]. It is worth to remember that XOR and NOT operations are reversible. XOR is reversible because <span class=\"math inline\">$latex \\forall x: x\\oplus x = 0 $<\/span> then <span class=\"math inline\">$latex x\\oplus y \\oplus y = x $<\/span>. NOT operation is reversible because doubling negation cancels it so <span class=\"math inline\">$latex \\neg \\neg x = x $<\/span>.\r\n\r\nSometimes these four operations are displayed on truth tables that let easily and quickly find out the result of operation assuming known values of two arguments: <span class=\"math inline\">$latex x $<\/span> and <span class=\"math inline\">$latex y $<\/span>. They are presented in tables [1.2], [1.3], [1.4], [1.5].\r\n\r\nIn computer logic operations usually are not done on single bits but whole bytes, words and so on. In such case bits are compared pairwise and the result has length equal to number of bits compared.\r\n<table style=\"width: 575px; height: 97px;\"><caption>Table 1.1: Four basic boolean operations.<\/caption>\r\n<thead>\r\n<tr class=\"header\" style=\"height: 13px;\">\r\n<th style=\"text-align: center; width: 82.5px; height: 13px;\"><strong>Name<\/strong><\/th>\r\n<th style=\"text-align: center; width: 73.4091px; height: 13px;\"><strong>Operation<\/strong><\/th>\r\n<th style=\"text-align: center; width: 73.4091px; height: 13px;\"><strong>Symbol<\/strong><\/th>\r\n<th style=\"text-align: center; width: 197.955px; height: 13px;\"><\/th>\r\n<th style=\"text-align: center; width: 149.773px; height: 13px;\"><\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\" style=\"height: 29px;\">\r\n<td style=\"text-align: center; width: 82.5px; height: 29px;\">Conjunction<\/td>\r\n<td style=\"text-align: center; width: 74.3182px; height: 29px;\">AND<\/td>\r\n<td style=\"text-align: center; width: 74.3182px; height: 29px;\"><span class=\"math inline\">$latex \\wedge $<\/span><\/td>\r\n<td style=\"text-align: center; width: 198.864px; height: 29px;\"><span class=\"math inline\">$latex x\\wedge y = 1 $<\/span> if <span class=\"math inline\">$latex x = y = 1 $<\/span><\/td>\r\n<td style=\"text-align: center; width: 150.682px; height: 29px;\">otherwise <span class=\"math inline\">$latex x\\wedge y = 0 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 13px;\">\r\n<td style=\"text-align: center; width: 82.5px; height: 13px;\">Disjunction<\/td>\r\n<td style=\"text-align: center; width: 74.3182px; height: 13px;\">OR<\/td>\r\n<td style=\"text-align: center; width: 74.3182px; height: 13px;\"><span class=\"math inline\">$latex \\vee $<\/span><\/td>\r\n<td style=\"text-align: center; width: 198.864px; height: 13px;\"><span class=\"math inline\">$latex x\\vee y = 0 $<\/span> if <span class=\"math inline\">$latex x = y = 0 $<\/span><\/td>\r\n<td style=\"text-align: center; width: 150.682px; height: 13px;\">otherwise <span class=\"math inline\">$latex x\\vee y = 1 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 29px;\">\r\n<td style=\"text-align: center; width: 82.5px; height: 29px;\">Exclusive or<\/td>\r\n<td style=\"text-align: center; width: 74.3182px; height: 29px;\">XOR<\/td>\r\n<td style=\"text-align: center; width: 74.3182px; height: 29px;\"><span class=\"math inline\">$latex \\oplus $<\/span><\/td>\r\n<td style=\"text-align: center; width: 198.864px; height: 29px;\"><span class=\"math inline\">$latex x\\oplus y = 1 $<\/span> if <span class=\"math inline\">$latex x \\neq y $<\/span><\/td>\r\n<td style=\"text-align: center; width: 150.682px; height: 29px;\">otherwise <span class=\"math inline\">$latex x\\oplus y = 0 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 13px;\">\r\n<td style=\"text-align: center; width: 82.5px; height: 13px;\">Negation<\/td>\r\n<td style=\"text-align: center; width: 74.3182px; height: 13px;\">NOT<\/td>\r\n<td style=\"text-align: center; width: 74.3182px; height: 13px;\"><span class=\"math inline\">$latex \\neg $<\/span><\/td>\r\n<td style=\"text-align: center; width: 198.864px; height: 13px;\"><span class=\"math inline\">$latex \\neg x = 1 $<\/span> if <span class=\"math inline\">$latex x = 0 $<\/span><\/td>\r\n<td style=\"text-align: center; width: 150.682px; height: 13px;\">otherwise <span class=\"math inline\">$latex \\neg x = 0 $<\/span><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<table style=\"width: 530px; height: 52px;\"><caption>Table 1.2: Conjunction truth table.<\/caption>\r\n<tbody>\r\n<tr class=\"odd\" style=\"height: 13px;\">\r\n<td style=\"text-align: left; width: 112.5px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 188.864px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 150.682px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 141.591px; height: 13px;\"><\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 13px;\">\r\n<td style=\"text-align: left; width: 112.5px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 188.864px; height: 13px;\"><strong>AND <\/strong><span class=\"math inline\">$latex x\\wedge y$<\/span><\/td>\r\n<td style=\"text-align: left; width: 150.682px; height: 13px;\"><strong>0<\/strong><\/td>\r\n<td style=\"text-align: left; width: 141.591px; height: 13px;\"><strong>1<\/strong><\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 13px;\">\r\n<td style=\"text-align: left; width: 112.5px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 188.864px; height: 13px;\"><strong>0<\/strong><\/td>\r\n<td style=\"text-align: left; width: 150.682px; height: 13px;\">0<\/td>\r\n<td style=\"text-align: left; width: 141.591px; height: 13px;\">0<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 13px;\">\r\n<td style=\"text-align: left; width: 112.5px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 188.864px; height: 13px;\"><strong>1<\/strong><\/td>\r\n<td style=\"text-align: left; width: 150.682px; height: 13px;\">0<\/td>\r\n<td style=\"text-align: left; width: 141.591px; height: 13px;\">1<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<table style=\"width: 488px;\"><caption>Table 1.3: Disjunction truth table.<\/caption>\r\n<tbody>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 107.955px;\"><\/td>\r\n<td style=\"text-align: left; width: 178.864px;\"><\/td>\r\n<td style=\"text-align: left; width: 180.682px;\"><\/td>\r\n<td style=\"text-align: left; width: 126.136px;\"><\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 107.955px;\"><\/td>\r\n<td style=\"text-align: left; width: 178.864px;\"><strong>OR <span class=\"math inline\">$latex x\\vee y$<\/span><\/strong><\/td>\r\n<td style=\"text-align: left; width: 180.682px;\"><strong>0<\/strong><\/td>\r\n<td style=\"text-align: left; width: 126.136px;\">1<\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 107.955px;\"><\/td>\r\n<td style=\"text-align: left; width: 178.864px;\"><strong>0<\/strong><\/td>\r\n<td style=\"text-align: left; width: 180.682px;\">0<\/td>\r\n<td style=\"text-align: left; width: 126.136px;\">1<\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 107.955px;\"><\/td>\r\n<td style=\"text-align: left; width: 178.864px;\"><strong>1<\/strong><\/td>\r\n<td style=\"text-align: left; width: 180.682px;\">1<\/td>\r\n<td style=\"text-align: left; width: 126.136px;\">1<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<table style=\"width: 502px;\"><caption>Table 1.4: Exclusive disjunction truth table.<\/caption>\r\n<tbody>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 37.9545px;\"><\/td>\r\n<td style=\"text-align: left; width: 237.955px;\"><\/td>\r\n<td style=\"text-align: left; width: 133.409px;\"><\/td>\r\n<td style=\"text-align: left; width: 184.318px;\"><\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 37.9545px;\"><\/td>\r\n<td style=\"text-align: left; width: 237.955px;\"><strong>XOR <span class=\"math inline\">$latex x\\oplus y$<\/span><\/strong><\/td>\r\n<td style=\"text-align: left; width: 133.409px;\"><strong>0<\/strong><\/td>\r\n<td style=\"text-align: left; width: 184.318px;\"><strong>1<\/strong><\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 37.9545px;\"><\/td>\r\n<td style=\"text-align: left; width: 237.955px;\"><strong>0<\/strong><\/td>\r\n<td style=\"text-align: left; width: 133.409px;\">0<\/td>\r\n<td style=\"text-align: left; width: 184.318px;\">1<\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 37.9545px;\"><\/td>\r\n<td style=\"text-align: left; width: 237.955px;\"><strong>1<\/strong><\/td>\r\n<td style=\"text-align: left; width: 133.409px;\">1<\/td>\r\n<td style=\"text-align: left; width: 184.318px;\">0<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<table style=\"width: 472px; height: 55px;\"><caption>Table 1.5: Negation truth table.<\/caption>\r\n<tbody>\r\n<tr class=\"odd\" style=\"height: 13px;\">\r\n<td style=\"text-align: left; width: 174.318px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 177.045px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 200.682px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 41.5909px; height: 13px;\"><\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 29px;\">\r\n<td style=\"text-align: left; width: 174.318px; height: 29px;\"><span class=\"math inline\"><strong>NEG<\/strong> $latex \\neg x$<\/span><\/td>\r\n<td style=\"text-align: left; width: 177.045px; height: 29px;\"><strong>0<\/strong><\/td>\r\n<td style=\"text-align: left; width: 200.682px; height: 29px;\"><strong>1<\/strong><\/td>\r\n<td style=\"text-align: left; width: 41.5909px; height: 29px;\"><\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 13px;\">\r\n<td style=\"text-align: left; width: 174.318px; height: 13px;\"><\/td>\r\n<td style=\"text-align: left; width: 177.045px; height: 13px;\">1<\/td>\r\n<td style=\"text-align: left; width: 200.682px; height: 13px;\">0<\/td>\r\n<td style=\"text-align: left; width: 41.5909px; height: 13px;\"><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<h2 id=\"hexadecimal-numbers\">Hexadecimal Numbers<\/h2>\r\nHexadecimal mode is also positional mode so it works exactly the same way as decimal and binary modes. The base in hexadecimal mode equals to 16 so 16 digits are necessary. First five letters from latin alphabet (A-F) expand standard decimal digits 0-9 making altogether 16 digits. Capital and small letters might be used but should not be mixed in single number. In the table below they are presented with their decimal values:\r\n<table style=\"width: 421px;\">\r\n<thead>\r\n<tr class=\"header\">\r\n<th style=\"text-align: left; width: 216.136px;\">Hexadecimal number<\/th>\r\n<th style=\"text-align: left; width: 13.4091px;\"><\/th>\r\n<th style=\"text-align: left; width: 12.5px;\">0<\/th>\r\n<th style=\"text-align: left; width: 10.6818px;\">1<\/th>\r\n<th style=\"text-align: left; width: 27.9545px;\">2<\/th>\r\n<th style=\"text-align: left; width: 17.0455px;\">3<\/th>\r\n<th style=\"text-align: left; width: 30.6818px;\">4<\/th>\r\n<th style=\"text-align: left; width: 28.8636px;\">5<\/th>\r\n<th style=\"text-align: left; width: 28.8636px;\">6<\/th>\r\n<th style=\"text-align: left; width: 27.0455px;\">7<\/th>\r\n<th style=\"text-align: left; width: 30.6818px;\">\u2026<\/th>\r\n<th style=\"text-align: left; width: 36.1364px;\"><\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 216.136px;\">Decimal value<\/td>\r\n<td style=\"text-align: left; width: 14.3182px;\"><\/td>\r\n<td style=\"text-align: left; width: 13.4091px;\">0<\/td>\r\n<td style=\"text-align: left; width: 11.5909px;\">1<\/td>\r\n<td style=\"text-align: left; width: 28.8636px;\">2<\/td>\r\n<td style=\"text-align: left; width: 17.9545px;\">3<\/td>\r\n<td style=\"text-align: left; width: 31.5909px;\">4<\/td>\r\n<td style=\"text-align: left; width: 29.7727px;\">5<\/td>\r\n<td style=\"text-align: left; width: 29.7727px;\">6<\/td>\r\n<td style=\"text-align: left; width: 27.9545px;\">7<\/td>\r\n<td style=\"text-align: left; width: 31.5909px;\">\u2026<\/td>\r\n<td style=\"text-align: left; width: 37.0455px;\"><\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 216.136px;\">Hexadecimal number<\/td>\r\n<td style=\"text-align: left; width: 14.3182px;\">\u2026<\/td>\r\n<td style=\"text-align: left; width: 13.4091px;\">8<\/td>\r\n<td style=\"text-align: left; width: 11.5909px;\">9<\/td>\r\n<td style=\"text-align: left; width: 28.8636px;\">A<\/td>\r\n<td style=\"text-align: left; width: 17.9545px;\">B<\/td>\r\n<td style=\"text-align: left; width: 31.5909px;\">C<\/td>\r\n<td style=\"text-align: left; width: 29.7727px;\">D<\/td>\r\n<td style=\"text-align: left; width: 29.7727px;\">E<\/td>\r\n<td style=\"text-align: left; width: 27.9545px;\">F<\/td>\r\n<td style=\"text-align: left; width: 31.5909px;\"><\/td>\r\n<td style=\"text-align: left; width: 37.0455px;\"><\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 216.136px;\">Decimal value<\/td>\r\n<td style=\"text-align: left; width: 14.3182px;\">\u2026<\/td>\r\n<td style=\"text-align: left; width: 13.4091px;\">8<\/td>\r\n<td style=\"text-align: left; width: 11.5909px;\">9<\/td>\r\n<td style=\"text-align: left; width: 28.8636px;\">10<\/td>\r\n<td style=\"text-align: left; width: 17.9545px;\">11<\/td>\r\n<td style=\"text-align: left; width: 31.5909px;\">12<\/td>\r\n<td style=\"text-align: left; width: 29.7727px;\">13<\/td>\r\n<td style=\"text-align: left; width: 29.7727px;\">14<\/td>\r\n<td style=\"text-align: left; width: 27.9545px;\">15<\/td>\r\n<td style=\"text-align: left; width: 31.5909px;\"><\/td>\r\n<td style=\"text-align: left; width: 37.0455px;\"><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\nHexadecimal values are very useful and popular representation of integer numbers, memory addresses and other numbers in programming and computing machinery. One and only one of several suffixes and prefixes should be used to indicate that given number is hexadecimal value. Sometimes suffixes and prefixes are not present as it might be assumed or it is known that given number is hexadecimal. Examples:\r\n<ul>\r\n \t<li><strong>0x<\/strong>1245 \u2013 this is hexadecimal number prefixed with \u201c0x\u201d despite no letter is present in the number<\/li>\r\n \t<li>3f78<strong>h<\/strong> \u2013 this is hexadecimal number as it is suffixed with \u201ch\u201d letter at the end<\/li>\r\n \t<li><strong>$<\/strong>68000 \u2013 dollar sign was used to prefix hexadecimal values on some systems but it is rarely used nowadays as it might be confused with other meanings of the dollar sign in source code<\/li>\r\n \t<li>C0DE \u2013 we may guess it is hexadecimal value because typical digits\u2013letters are present<\/li>\r\n<\/ul>\r\nConversion from decimal mode to hexadecimal might be done in the same way as it is done between decimal and binary. In the following example a decimal value 40375 will be converted to its hexadecimal representation:\r\n\r\n<span class=\"math display\">$latex \\begin{aligned}\r\n40375 = 16 \\times 2523 + 7 \\\\\r\n2523 = 16 \\times 157 + 11 \\\\\r\n157 = 16 \\times 9 + 13 \\\\\r\n9 = 16 \\times 0 + 9\\end{aligned} $<\/span>\r\n\r\nRemainders are as follows: 7, 11, 13, 9 or when represented as hexadecimal digits they are: 7, B, D, 9. Therefore 40375d = 0x9db7.\r\n\r\nNow we try method based on subtractions knowing that <span class=\"math inline\">$latex 16^0=1 $<\/span>, <span class=\"math inline\">$latex 16^2=256 $<\/span>, <span class=\"math inline\">$latex 16^3=4096 $<\/span>. In every step we will look for the biggest value that can be subtracted that is also a product of the base mentioned earlier and term that is lesser or equal to 15 (0xf).\r\n\r\n<span class=\"math display\">$latex \\begin{aligned}\r\n40375 - (9 * 4096) &amp;= 3511 \\\\\r\n3511 - (13 * 256) &amp;= 183 \\\\\r\n183 - (11 * 16) &amp;= 7 \\\\\r\n7d - (7 * 1) &amp;= 0 \\end{aligned} $<\/span>\r\n<h2 id=\"section:integers\">Integers<\/h2>\r\nThe simplest, unsigned integers are simple binary representation of specific value just as it was discussed in section\u00a0<a href=\"#section:binary\" data-reference-type=\"ref\" data-reference=\"section:binary\">1.1<\/a>. Number of possible values and their ranges depends on bits used to represent the number. Characteristic data formats and their corresponding maximum unsigned numbers are shown in table\u00a0<a href=\"#tab:unsignedlimits\" data-reference-type=\"ref\" data-reference=\"tab:unsignedlimits\">1.6<\/a>. Limits of addressable space are theoretical maximums and do not consider caps such as: physical limitations of actual memory modules, hardware limitations of computer mainboard and software implementation introduced by operating systems.\r\n<table style=\"width: 588px; height: 322px;\"><caption id=\"tab:unsignedlimits\">Table 1.6: Unsigned integers and their limits in typical data formats.<\/caption>\r\n<thead>\r\n<tr class=\"header\" style=\"height: 14px;\">\r\n<th style=\"text-align: left; width: 153.409px; height: 14px;\">Number of bits<\/th>\r\n<th style=\"text-align: left; width: 156.136px; height: 14px;\">Maximum unsigned<\/th>\r\n<th style=\"text-align: left; width: 295.227px; height: 14px;\">Remarks<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">1<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">1<\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Bit<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">4<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">15<\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Half-byte (nibble)<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">8<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">255<\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Byte<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">10<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">1023<\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Typical in ADC<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">12<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">4095<\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Typical in ADC<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">16<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">65535<\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Word; 64 kB addressable<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">32<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">4294967295<\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Double-word; 4 GB addressable<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">42<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\"><span class=\"math inline\">$latex 2^{42} - 1 $<\/span><\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">x86_64 Intel CPU addressable space \u2013 4 TB<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">48<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\"><span class=\"math inline\">$latex 2^{48} - 1 $<\/span><\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">x86_64 AMD CPU addressable space \u2013 256 TB<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 14px;\">\r\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">64<\/td>\r\n<td style=\"text-align: left; width: 157.045px; height: 14px;\"><span class=\"math inline\">$latex 2^{64} - 1 $<\/span><\/td>\r\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Quad-word; 16 PB addressable<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<h3 id=\"signed-magnitude-integers\">Signed-magnitude Integers<\/h3>\r\nOne bit may be designated to store information about the sign of value. If there is 0 on that bit then value is considered to be positive, otherwise it is negative. Limits of several exemplary data formats are given in table\u00a0<a href=\"#tab:signedlimits\" data-reference-type=\"ref\" data-reference=\"tab:signedlimits\">1.7<\/a>.\r\n<table style=\"width: 547px;\"><caption id=\"tab:signedlimits\">Table 1.7: Signed-magnitude integers and their limits in typical data formats.<\/caption>\r\n<thead>\r\n<tr class=\"header\">\r\n<th style=\"text-align: left; width: 132.5px;\">Number of bits<\/th>\r\n<th style=\"text-align: left; width: 199.773px;\">Limits<\/th>\r\n<th style=\"text-align: left; width: 272.5px;\">Remarks<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 132.5px;\">4<\/td>\r\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">$latex \\pm $<\/span>7<\/td>\r\n<td style=\"text-align: left; width: 273.409px;\">Half-byte (nibble)<\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 132.5px;\">8<\/td>\r\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">$latex \\pm $<\/span>127<\/td>\r\n<td style=\"text-align: left; width: 273.409px;\">Byte<\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 132.5px;\">10<\/td>\r\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">$latex \\pm $<\/span>511<\/td>\r\n<td style=\"text-align: left; width: 273.409px;\">Typical in ADC<\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 132.5px;\">12<\/td>\r\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">$latex \\pm $<\/span>2047<\/td>\r\n<td style=\"text-align: left; width: 273.409px;\">Typical in ADC<\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 132.5px;\">16<\/td>\r\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">$latex \\pm $<\/span>32767<\/td>\r\n<td style=\"text-align: left; width: 273.409px;\">Word<\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 132.5px;\">32<\/td>\r\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">$latex \\pm $<\/span>2147483647<\/td>\r\n<td style=\"text-align: left; width: 273.409px;\">Double-word; <span class=\"math inline\">$latex \\pm $<\/span>2 billions<\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 132.5px;\">64<\/td>\r\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">$latex 2^{64-1} - 1 $<\/span><\/td>\r\n<td style=\"text-align: left; width: 273.409px;\">Quad-word; <span class=\"math inline\">$latex \\pm $<\/span>9 quintillions<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\nWith signed-magnitude integers there is significant problem of doubled zero as there are two possible values that represent \u201cpositive\u201d (000..00000) and \u201cnegative\u201d (1000..000) zeros. Sum of these two zeros results in \u201cnegative\u201d zero.\r\n\r\nFurthermore sum of positive and negative values that have their absolutes equal is not that straightforward. For example lets sum signed-magnitude values of -5 and +5. Assuming that they are stored in 4-bit registers their representations are: 1101 and 0101, where first (most significant) bit represents sign. Direct sum in bit pairwise order starting at the least significant results in 0010 which is <span class=\"math inline\">$latex +2 $<\/span> that is not the correct answer.\r\n\r\nWith signed-magnitude one needs to take sign bit into consideration first. If the bit is the same in both values then they should be added and their sign bit copied. If they have different sign bit then they should be subtracted and bit is copied from the absolutely larger value. This approach is complex and slow thus was superseded by one\u2019s complement and two\u2019s complement representations.\r\n<h3 id=\"ones-complement-and-twos-complement\">One\u2019s Complement and Two\u2019s Complement<\/h3>\r\nIn one\u2019s complement to represent negative number its positive (absolute) binary representation is bitwise inverted with NOT operation. Therefore negative numbers in one\u2019s complement can be recognized by 1 in the most significant bit. So <span class=\"math inline\">$latex +5 $<\/span> from previous example is still 0101 but <span class=\"math inline\">$latex -5 $<\/span> is 1010. Summing them up results in 1111 that is one of two possible representations of zero. The zero in one\u2019s complement is represented by either 0 on all bits so that it is <span class=\"math inline\">$latex 0^+ $<\/span> or 1 on all bits so it is <span class=\"math inline\">$latex 0^- $<\/span>.\r\n\r\nProblem of doubled zero is finally solved in two\u2019s complement. In two\u2019s complement zero has no sign because it is represented only by all bits set to 0.\r\n\r\nTo convert negative (and only negative!) value from binary to two\u2019s complement one has to simply add one to one\u2019s complement of the value. Therefore <span class=\"math inline\">$latex +5 $<\/span> is still <span class=\"math inline\">$latex 0101 $<\/span> in two\u2019s complement. However, <span class=\"math inline\">$latex -5 $<\/span> = 1010 in one\u2019s complement so it is 1011 in two\u2019s complement. If we add these two two\u2019s complement values: 0101 and 1011 the result is <strong>1<\/strong>0000 so it is lengthier than original but in the basis all bits will be equal to zero. This additional bit might be indication of the result equal to zero.\r\n\r\nTo convert two\u2019s complement that is negative, so one which has the most significant bit set, back to binary representation both previous operations must be performed but in reversed order. So it is necessary to subtract one and invert all bits. For example all \u201cones\u201d (11..11) is a negative value which after subtraction becomes (11..110), and after inversion it is 00..001 so we conclude that it represented <span class=\"math inline\">$latex -1 $<\/span> in decimal.\r\n\r\nFurther examples are given in table\u00a0<a href=\"#tab:twos\" data-reference-type=\"ref\" data-reference=\"tab:twos\">1.8<\/a>. Interesting fact about two\u2019s complement is that this format can represent less positive values than negative values by one.\r\n\r\nTwo\u2019s complement might look complicated on paper but is not an issue for computing machinery. It is an ultimate solution to all problems discussed above so it is commonly implemented in contemporary processors.\r\n<table style=\"width: 603px; height: 225px;\"><caption>Table 1.8: Some exemplary two\u2019s complement values on 8-bit register.<\/caption>\r\n<thead>\r\n<tr class=\"header\" style=\"height: 15px;\">\r\n<th style=\"text-align: left; width: 146.136px; height: 15px;\">Value<\/th>\r\n<th style=\"text-align: left; width: 472.5px; height: 15px;\">Two\u2019s complement<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+127<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">01111111<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+32<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00100000<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+15<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00001111<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+3<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00000011<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+2<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00000010<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+1<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00000001<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">0<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00000000<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-1<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11111111<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-2<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11111110<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-3<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11111101<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-15<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11110001<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-32<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11100000<\/td>\r\n<\/tr>\r\n<tr class=\"odd\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-127<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">10000001<\/td>\r\n<\/tr>\r\n<tr class=\"even\" style=\"height: 15px;\">\r\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-128<\/td>\r\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">10000000<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<h2 id=\"fixed-point-and-floating-point-numbers\">Fixed-point and Floating-point Numbers<\/h2>\r\nElectronic circuitry and processors are capable of processing integer numbers quite efficiently. However, real numbers are a problem due to their possible high number of decimal places. The higher number of decimal places the larger is the precision with which the value needs to be stored and so more information it possesses. With increasing precision more bits are needed to store the real value.\r\n\r\nThere are two approaches to store real numbers in computing machinery: fixed-point and floating-point. First one has limited precision, an arbitrary number of decimal places and so its resolution is limited. Second method provides much higher resolutions and wider range of stored values but introduces an error as it is the best possible approximation with given number of bits used to store the floating point number.\r\n<h3 id=\"fixed-point-numbers\">Fixed-point numbers<\/h3>\r\nFixed-point number consists of two parts: integer and fractional. With given size of register some bits are used to store integer part and remaining ones are used to store fractional part. Integer part is stored as it was described in section\u00a0<a href=\"#section:integers\" data-reference-type=\"ref\" data-reference=\"section:integers\">1.3<\/a>. Bits in fractional part have base 2 but their exponents are negative. So there is <span class=\"math inline\">$latex 2^{-1}=\\frac{1}{2} $<\/span>, <span class=\"math inline\">$latex 2^{-2}=\\frac{1}{4} $<\/span>, <span class=\"math inline\">$latex 2^{-3}=\\frac{1}{8} $<\/span>. The series ends on <span class=\"math inline\">$latex 2^{-n}=\\frac{1}{2^n} $<\/span>, where <span class=\"math inline\">$latex n $<\/span> cannot be higher than number of bits in used register. Powers of 2 with exponent down to -8 are given in table\u00a0<a href=\"#tab:fractionals\" data-reference-type=\"ref\" data-reference=\"tab:fractionals\">1.9<\/a>.\r\n<table style=\"width: 497px;\"><caption>Table 1.9: Start of series of fractional parts in fixed-point mode.<\/caption>\r\n<thead>\r\n<tr class=\"header\">\r\n<th style=\"text-align: left; width: 186.136px;\"><span class=\"math inline\">$latex n $<\/span><\/th>\r\n<th style=\"text-align: left; width: 432.5px;\"><span class=\"math inline\">$latex x^n $<\/span><\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 186.136px;\">-1<\/td>\r\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">$latex 0.5 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 186.136px;\">-2<\/td>\r\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">$latex 0.25 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 186.136px;\">-3<\/td>\r\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">$latex 0.125 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 186.136px;\">-4<\/td>\r\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">$latex 0.0625 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 186.136px;\">-5<\/td>\r\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">$latex 0.03125 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 186.136px;\">-6<\/td>\r\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">$latex 0.015625 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 186.136px;\">-7<\/td>\r\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">$latex 0.0078125 $<\/span><\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 186.136px;\">-8<\/td>\r\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">$latex 0.00390625 $<\/span><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\nFixed-point is an arbitrary data storage mode as programmers implementing it may choose how many bits should be used per each part. Example below presents fixed-point storage on 8-bit register with 3 bits used to store integer part and 5 to store fractional part. Number that we would like to store in this \u201c<span class=\"math inline\">$latex 3.5 $<\/span>\u201d format is <span class=\"math inline\">$latex 5.789306640625 $<\/span>.\r\n\r\nConverting decimal 5 to binary results in 101 and these bits will occupy upper part of the register (more significant bits). Now do repetitive subtractions, if they are possible. If subtraction was possible then corresponding fractional bit should be set.\r\n\r\n<span class=\"math display\">$latex \\begin{aligned}\r\n0.789306640625 -&amp; 0.5 &amp;=&amp; 0.289306640625 &amp; \\Rightarrow 1 \\\\\r\n0.289306640625 -&amp; 0.25 &amp;=&amp; 0.039306640625 &amp; \\Rightarrow 1 \\\\\r\n0.039306640625 -&amp; 0.125 &amp;&amp;lt;&amp; 0 &amp; \\Rightarrow 0 \\\\\r\n0.039306640625 -&amp; 0.0625 &amp;&amp;lt;&amp; 0 &amp; \\Rightarrow 0 \\\\\r\n0.039306640625 -&amp; 0.03125 &amp;=&amp; 0.008056640625 &amp; \\Rightarrow 1 \\end{aligned} $<\/span>\r\n\r\nSo decimal <span class=\"math inline\">$latex 5.789306640625 = 10111001_{3.5} $<\/span>. Remainder equals to <span class=\"math inline\">$latex 0.008056640625 $<\/span> and this is the error introduced due to conversion.\r\n\r\nConversion back is more straightforward: <span class=\"math inline\">$latex 1\\times2^2 + 1\\times2^0 + 1\\times2^{-1} + 1\\times2^{-2} + 1\\times2^{-5} = 5.78125 $<\/span>. Difference between original value and recovered one equals to remainder that we had to abandon during conversion from decimal to fixed-point.\r\n<h3 id=\"floating-point-numbers\">Floating-point numbers<\/h3>\r\nFloating-point number can represent highly varying range of values both very large and very small. Contemporary processors provide implementation of IEEE standard\u00a0 that is well established description of floating-point number formats.\r\n\r\nConversion between decimal value and its IEEE\u00a0754 representation is given by equation: <span class=\"math display\">$latex L_{10} = (-1)^s\\,(1+m)\\,b^{e-x} $<\/span>\r\n\r\nwhere:\r\n<ul>\r\n \t<li><span class=\"math inline\">$latex L_{10} $<\/span> \u2013 decimal value<\/li>\r\n \t<li>s \u2013 one bit that represents sign<\/li>\r\n \t<li>m \u2013 mantissa that is fractional part<\/li>\r\n \t<li>b \u2013 base (radix) that in computer machinery usually is 2<\/li>\r\n \t<li>e \u2013 exponent<\/li>\r\n \t<li>x \u2013 maximum possible value of exponent (exponent bias) <span class=\"math inline\">$latex x = 2^k - 2 $<\/span>, where k is number of exponent bits.<\/li>\r\n<\/ul>\r\nRange and precision depend on the number of bits alloted to mantissa and exponent. Some examples are shown in table\u00a0<a href=\"#tab:floatbits\" data-reference-type=\"ref\" data-reference=\"tab:floatbits\">1.10<\/a>. Effective, calculated exponent value E have to be within ranges presented in table\u00a0<a href=\"#tab:floatlimits\" data-reference-type=\"ref\" data-reference=\"tab:floatlimits\">1.11<\/a>.\r\n<table style=\"width: 543px;\"><caption>Table 1.10: Some IEEE 754 modes with base 2.<\/caption>\r\n<thead>\r\n<tr class=\"header\">\r\n<th style=\"text-align: left; width: 201.591px;\">Name<\/th>\r\n<th style=\"text-align: left; width: 112.5px;\">Bits total<\/th>\r\n<th style=\"text-align: left; width: 113.409px;\">Mantissa bits<\/th>\r\n<th style=\"text-align: left; width: 163.409px;\">Exponent bits<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 201.591px;\">Half precision<\/td>\r\n<td style=\"text-align: left; width: 113.409px;\">16<\/td>\r\n<td style=\"text-align: left; width: 114.318px;\">10<\/td>\r\n<td style=\"text-align: left; width: 164.318px;\">5<\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 201.591px;\">Single precision<\/td>\r\n<td style=\"text-align: left; width: 113.409px;\">32<\/td>\r\n<td style=\"text-align: left; width: 114.318px;\">23<\/td>\r\n<td style=\"text-align: left; width: 164.318px;\">8<\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 201.591px;\">Double precision<\/td>\r\n<td style=\"text-align: left; width: 113.409px;\">64<\/td>\r\n<td style=\"text-align: left; width: 114.318px;\">52<\/td>\r\n<td style=\"text-align: left; width: 164.318px;\">11<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n.\r\n<table style=\"width: 628px;\"><caption>Table 1.11: Exponent limits in popular IEEE 754 formats.<\/caption>\r\n<thead>\r\n<tr class=\"header\">\r\n<th style=\"text-align: left; width: 167.045px;\">Name<\/th>\r\n<th style=\"text-align: left; width: 148.864px;\"><span class=\"math inline\">$latex e_{max} $<\/span><\/th>\r\n<th style=\"text-align: left; width: 154.318px;\"><span class=\"math inline\">$latex E_{min} $<\/span><\/th>\r\n<th style=\"text-align: left; width: 120.682px;\"><span class=\"math inline\">$latex E_{max} = x $<\/span><\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 167.045px;\">Half precision<\/td>\r\n<td style=\"text-align: left; width: 149.773px;\">30<\/td>\r\n<td style=\"text-align: left; width: 155.227px;\">-14<\/td>\r\n<td style=\"text-align: left; width: 121.591px;\">+15<\/td>\r\n<\/tr>\r\n<tr class=\"even\">\r\n<td style=\"text-align: left; width: 167.045px;\">Single precision<\/td>\r\n<td style=\"text-align: left; width: 149.773px;\">254<\/td>\r\n<td style=\"text-align: left; width: 155.227px;\">-126<\/td>\r\n<td style=\"text-align: left; width: 121.591px;\">+127<\/td>\r\n<\/tr>\r\n<tr class=\"odd\">\r\n<td style=\"text-align: left; width: 167.045px;\">Double precision<\/td>\r\n<td style=\"text-align: left; width: 149.773px;\">2046<\/td>\r\n<td style=\"text-align: left; width: 155.227px;\">-1022<\/td>\r\n<td style=\"text-align: left; width: 121.591px;\">+1023<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\nExamples in half precision: <span class=\"math display\">$latex \\begin{aligned}\r\n0\\; &amp; 01111 &amp; 0000000001 &amp; = &amp; (-1)^0 &amp;\\times&amp; 2^{15 - 15} &amp; \\times &amp; (1 + 2^{-10}) &amp;=&amp; 1.0009765625 \\\\\r\n0\\; &amp; 00001 &amp; 1000000001 &amp; = &amp; (-1)^0 &amp;\\times&amp; 2^{1 - 15} &amp; \\times &amp; (1 + 2^{-1} + 2^{-10}) &amp;=&amp; 0.0000916123 \\\\\r\n1\\; &amp; 10001 &amp; 1000000000 &amp; = &amp; (-1)^1 &amp;\\times&amp; 2^{17 - 15} &amp; \\times &amp; (1 + 2^{-1}) &amp;=&amp; -6.0\\end{aligned} $<\/span>\r\n\r\nExamples in single precision: <span class=\"math display\">$latex \\begin{aligned}\r\n0\\; 01111111 \\; 01000000000000000000000 &amp;= 2^{127 - 127} \\times (1 + 2^{-2}) &amp;= 1.25 \\\\\r\n0\\; 10000010 \\; 11000000000000000000000 &amp;= 2^{130 - 127} \\times (1 + 2^{-1} + 2^{-2}) &amp;= 14.0 \\\\\r\n1\\; 00000001 \\; 00000000000000000000000 &amp;= 2^{1 - 127} \\times 1 &amp;= -1.1755e-38 \\\\\r\n1\\; 11111110 \\; 11111111111111111111111 &amp;\\approx 2^{254 - 127} \\times 2 &amp;= -3.40282e+38 \\\\\\end{aligned} $<\/span>\r\n\r\nIf all bits of exponent are set to zero then it is a category of denormalized values. In that situation exponent used in computation has <span class=\"math inline\">$latex E_{min} $<\/span> value as given by table\u00a0<a href=\"#tab:floatlimits\" data-reference-type=\"ref\" data-reference=\"tab:floatlimits\">1.11<\/a>. Mantissa takes form of 0.m instead of regular 1.m hence there is no addition of one to the mantissa. Denormalized values are used to store extremely small numbers. Example of denormalized number: <span class=\"math display\">$latex \\begin{aligned}\r\n0\\; 00000000 \\; 00000000000000000000001 &amp;= \\\\\r\n2^{-126} \\times (0 + 2^{-23}) &amp;= 1e-45 \\\\\\end{aligned} $<\/span>\r\n\r\nSome other compositions of bits also have special meaning:\r\n<ul>\r\n \t<li>+0 \u2013 all bits set to zero<\/li>\r\n \t<li>-0 \u2013 all bits set to zero except of sign bit which is set to one<\/li>\r\n \t<li>+Infinity \u2013 all exponent bits set to one, e.g.: 0 11111111 00000000000000000000000<\/li>\r\n \t<li>-Infinity \u2013 all exponent bits set to one, e.g.: 1 11111111 00000000000000000000000<\/li>\r\n \t<li>NaN \u2013 \u201cNot a number\u201d so result of operation such as division by zero is indicated by sign bit set to one, all exponent bits set to one, and at least one of mantissa bits set to one; e.g.: 1 11111111 00000000000000000000001<\/li>\r\n<\/ul>\r\n<h2 id=\"endianness\">Endianness<\/h2>\r\nData of any kind in computer memory must be stored consistently and orderly. This order is known as endianness. Non-technical people also use endianness when they want to save date, which may have many formats, as for example:\r\n<ul>\r\n \t<li>13<sup>th<\/sup> of December, 1981<\/li>\r\n \t<li>December 13, 1981<\/li>\r\n \t<li>1981-12-13<\/li>\r\n<\/ul>\r\nComputer memory might be imagined as a series of data cells. Some microcontrollers enable to access single bits but usually bytes are the smallest units available. Second order data units like words, double-words, quad-words consist of more than one byte and these bytes are stored in computer memory in specific order.\r\n\r\nWhen big-endian is used then with increasing addresses bytes are stored starting from the least significant one (representing smaller values). In little endian it is otherwise so when memory is read byte by byte then data looks like bytes have reversed order. Little endian system is used in x86_64 architecture. These two endiannesses are shown on figure\u00a0<a href=\"#fig:endianness\" data-reference-type=\"ref\" data-reference=\"fig:endianness\">1.1<\/a>.\r\n<figure>\r\n\r\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"355\"]<img class=\" wp-image-38\" src=\"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-content\/uploads\/sites\/16\/2019\/08\/img_5d5128ca31f37.png\" alt=\"\" width=\"355\" height=\"187\" \/> Figure 1.1 Comparison of big-endian and little-endian with one byte unit.[\/caption]\r\n\r\n<figcaption><\/figcaption><\/figure>\r\nIt is also possible to have different unit than single byte. In such case big-endian storage will have no difference to one shown in figure\u00a0<a href=\"#fig:endianness\" data-reference-type=\"ref\" data-reference=\"fig:endianness\">1.1<\/a>. However, if unit is for example word (two bytes) and 0xd1cec0de is to be stored then in memory it will be present as: 0xc0de, 0xd1ce. If the unit were one byte it would be stored as: 0xde, 0xc0, 0xce, 0xd1.","rendered":"<blockquote>\n<p style=\"text-align: right;\"><em>Mathematics is the most beautiful and most<\/em><br \/>\n<em>powerful creation of the human spirit.<\/em><\/p>\n<p style=\"text-align: right;\">Stefan Banach<\/p>\n<\/blockquote>\n<p>Computer processors might be perceived as extremely efficient \u201cnumber crunchers\u201d which means that they process enormous streams of information expressed only with numbers. It is worth for engineers to understand various ways by which electronic systems process these numbers.<\/p>\n<p>Humans in almost every corner of the earth are used to decimal system. This is so easy and natural to count with fingers hence positional system based on powers of tens is the most common nowadays. It is well known in practice but revising it might be helpful in understanding other systems discussed here. Look at the example:<\/p>\n<p><span class=\"math display\">[latex]40375 = 4\\times10^4 + 0\\times10^3 + 3\\times10^2 + 7\\times10^1 + 5\\times10^0 = 40000 + 0 + 300 + 70 + 5[\/latex]<\/span><\/p>\n<p>In computer systems decimal numbers usually have no prefix or suffix but sometimes they are suffixed with \u201cd\u201d: <span class=\"math inline\">[latex]40375d[\/latex]<\/span>.<\/p>\n<h2 id=\"section:binary\">Binary System<\/h2>\n<p>Computers do not use decimal system. They are working on <em>bits<\/em> where bit is unit of information. It can have only one of two possible but different values such as:<\/p>\n<table style=\"width: 617px; height: 45px;\">\n<thead>\n<tr class=\"header\" style=\"height: 15px;\">\n<th style=\"text-align: center; width: 359.773px; height: 15px;\">True<\/th>\n<th style=\"text-align: center; width: 258.864px; height: 15px;\">False<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\" style=\"height: 15px;\">\n<td style=\"text-align: center; width: 359.773px; height: 15px;\">1<\/td>\n<td style=\"text-align: center; width: 259.773px; height: 15px;\">0<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 15px;\">\n<td style=\"text-align: center; width: 359.773px; height: 15px;\">Day<\/td>\n<td style=\"text-align: center; width: 259.773px; height: 15px;\">Night<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Binary system has only two digits: 0 and 1. It is also positional as decimal system, but the base equals 2 (that is number of digits). Binary numers sometimes are suffixed with letter \u201cb\u201d or prefixed with \u201c0b\u201d. In the following example every multiplicand is expressed in decimal mode but it was omitted to simplify the equation and make it easier to follow the process:<\/p>\n<p><span class=\"math display\">[latex]0b1011 = 1\\times2^3 + 0\\times2^2 + 1\\times2^1 + 1\\times2^0 = 1\\times8 + 0\\times4 + 1\\times2 + 1\\times1 = 8d + 2d + 1d = 11d[\/latex]<\/span><\/p>\n<p>Above example also shows how binary number is converted to decimal mode. The series of multiplicands (starting from the rightmost position) in this conversion is easy to understand, reproduce or even remember: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8129, 16384, 32768, 65536, \u2026<\/p>\n<p>Conversion in from decimal mode to binary is a bit more tricky and there are several ways to do it. First approach is repetitive division by 2 with remainder that indicates value of bit at specific position. Example:<\/p>\n<p><span class=\"math display\">[latex]\\begin{aligned}  11d = 2\\times5d + 1\\\\  5d = 2\\times2d + 1\\\\  2d = 2\\times1d + 0\\\\  1d = 2\\times0d + 1\\end{aligned}[\/latex]<\/span><\/p>\n<p>If we write remainders starting from the last one we will get binary value: <strong>1011<\/strong>b.<\/p>\n<p>The above method works well for any value. But for small values simpler method might be employed which is based on subtraction. However, it requires to know (e.g. remember) weights at different digit positions. In every step a biggest possible weight is subtracted from the number that is being converted provided that result will remain positive number. At positions with corresponding weights \u201cones\u201d are set leaving all other positions with \u201czeros\u201d. Example:<\/p>\n<p><span class=\"math display\">[latex]\\begin{aligned}  11d - 8d &= 3d \\qquad\\text{8d subtracted successfully so there should be ``1''}\\\\  3d - 0d &= 3d \\qquad\\text{4d cannot be subtracted within positive integers so ``0''}\\\\  3d - 2d &= 1d \\qquad\\text{2d subtracted successfully so there should be ``1''}\\\\  1d - 1d &= 0d \\qquad\\text{1d left so there should be ``1'' in the last position}\\end{aligned}[\/latex]<\/span><\/p>\n<p>This method may be much faster than previous one for small numbers. There is no threshold given how \u201csmall\u201d the number should be as it depends on experience of the person that is doing the conversion. Range of one nibble (4 bits) is easy to achieve while full byte (8 bits) is little harder, although even 12-bit values are possible to be converted by human being without neither calculator or pen and paper at hand.<\/p>\n<p>Binary system is foundation for boolean algebra. In typical computer implementations there are usually four basic operations available as presented in the table [1.1]. It is worth to remember that XOR and NOT operations are reversible. XOR is reversible because <span class=\"math inline\">[latex]\\forall x: x\\oplus x = 0[\/latex]<\/span> then <span class=\"math inline\">[latex]x\\oplus y \\oplus y = x[\/latex]<\/span>. NOT operation is reversible because doubling negation cancels it so <span class=\"math inline\">[latex]\\neg \\neg x = x[\/latex]<\/span>.<\/p>\n<p>Sometimes these four operations are displayed on truth tables that let easily and quickly find out the result of operation assuming known values of two arguments: <span class=\"math inline\">[latex]x[\/latex]<\/span> and <span class=\"math inline\">[latex]y[\/latex]<\/span>. They are presented in tables [1.2], [1.3], [1.4], [1.5].<\/p>\n<p>In computer logic operations usually are not done on single bits but whole bytes, words and so on. In such case bits are compared pairwise and the result has length equal to number of bits compared.<\/p>\n<table style=\"width: 575px; height: 97px;\">\n<caption>Table 1.1: Four basic boolean operations.<\/caption>\n<thead>\n<tr class=\"header\" style=\"height: 13px;\">\n<th style=\"text-align: center; width: 82.5px; height: 13px;\"><strong>Name<\/strong><\/th>\n<th style=\"text-align: center; width: 73.4091px; height: 13px;\"><strong>Operation<\/strong><\/th>\n<th style=\"text-align: center; width: 73.4091px; height: 13px;\"><strong>Symbol<\/strong><\/th>\n<th style=\"text-align: center; width: 197.955px; height: 13px;\"><\/th>\n<th style=\"text-align: center; width: 149.773px; height: 13px;\"><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\" style=\"height: 29px;\">\n<td style=\"text-align: center; width: 82.5px; height: 29px;\">Conjunction<\/td>\n<td style=\"text-align: center; width: 74.3182px; height: 29px;\">AND<\/td>\n<td style=\"text-align: center; width: 74.3182px; height: 29px;\"><span class=\"math inline\">[latex]\\wedge[\/latex]<\/span><\/td>\n<td style=\"text-align: center; width: 198.864px; height: 29px;\"><span class=\"math inline\">[latex]x\\wedge y = 1[\/latex]<\/span> if <span class=\"math inline\">[latex]x = y = 1[\/latex]<\/span><\/td>\n<td style=\"text-align: center; width: 150.682px; height: 29px;\">otherwise <span class=\"math inline\">[latex]x\\wedge y = 0[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 13px;\">\n<td style=\"text-align: center; width: 82.5px; height: 13px;\">Disjunction<\/td>\n<td style=\"text-align: center; width: 74.3182px; height: 13px;\">OR<\/td>\n<td style=\"text-align: center; width: 74.3182px; height: 13px;\"><span class=\"math inline\">[latex]\\vee[\/latex]<\/span><\/td>\n<td style=\"text-align: center; width: 198.864px; height: 13px;\"><span class=\"math inline\">[latex]x\\vee y = 0[\/latex]<\/span> if <span class=\"math inline\">[latex]x = y = 0[\/latex]<\/span><\/td>\n<td style=\"text-align: center; width: 150.682px; height: 13px;\">otherwise <span class=\"math inline\">[latex]x\\vee y = 1[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 29px;\">\n<td style=\"text-align: center; width: 82.5px; height: 29px;\">Exclusive or<\/td>\n<td style=\"text-align: center; width: 74.3182px; height: 29px;\">XOR<\/td>\n<td style=\"text-align: center; width: 74.3182px; height: 29px;\"><span class=\"math inline\">[latex]\\oplus[\/latex]<\/span><\/td>\n<td style=\"text-align: center; width: 198.864px; height: 29px;\"><span class=\"math inline\">[latex]x\\oplus y = 1[\/latex]<\/span> if <span class=\"math inline\">[latex]x \\neq y[\/latex]<\/span><\/td>\n<td style=\"text-align: center; width: 150.682px; height: 29px;\">otherwise <span class=\"math inline\">[latex]x\\oplus y = 0[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 13px;\">\n<td style=\"text-align: center; width: 82.5px; height: 13px;\">Negation<\/td>\n<td style=\"text-align: center; width: 74.3182px; height: 13px;\">NOT<\/td>\n<td style=\"text-align: center; width: 74.3182px; height: 13px;\"><span class=\"math inline\">[latex]\\neg[\/latex]<\/span><\/td>\n<td style=\"text-align: center; width: 198.864px; height: 13px;\"><span class=\"math inline\">[latex]\\neg x = 1[\/latex]<\/span> if <span class=\"math inline\">[latex]x = 0[\/latex]<\/span><\/td>\n<td style=\"text-align: center; width: 150.682px; height: 13px;\">otherwise <span class=\"math inline\">[latex]\\neg x = 0[\/latex]<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"width: 530px; height: 52px;\">\n<caption>Table 1.2: Conjunction truth table.<\/caption>\n<tbody>\n<tr class=\"odd\" style=\"height: 13px;\">\n<td style=\"text-align: left; width: 112.5px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 188.864px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 150.682px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 141.591px; height: 13px;\"><\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 13px;\">\n<td style=\"text-align: left; width: 112.5px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 188.864px; height: 13px;\"><strong>AND <\/strong><span class=\"math inline\">[latex]x\\wedge y[\/latex]<\/span><\/td>\n<td style=\"text-align: left; width: 150.682px; height: 13px;\"><strong>0<\/strong><\/td>\n<td style=\"text-align: left; width: 141.591px; height: 13px;\"><strong>1<\/strong><\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 13px;\">\n<td style=\"text-align: left; width: 112.5px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 188.864px; height: 13px;\"><strong>0<\/strong><\/td>\n<td style=\"text-align: left; width: 150.682px; height: 13px;\">0<\/td>\n<td style=\"text-align: left; width: 141.591px; height: 13px;\">0<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 13px;\">\n<td style=\"text-align: left; width: 112.5px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 188.864px; height: 13px;\"><strong>1<\/strong><\/td>\n<td style=\"text-align: left; width: 150.682px; height: 13px;\">0<\/td>\n<td style=\"text-align: left; width: 141.591px; height: 13px;\">1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"width: 488px;\">\n<caption>Table 1.3: Disjunction truth table.<\/caption>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 107.955px;\"><\/td>\n<td style=\"text-align: left; width: 178.864px;\"><\/td>\n<td style=\"text-align: left; width: 180.682px;\"><\/td>\n<td style=\"text-align: left; width: 126.136px;\"><\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 107.955px;\"><\/td>\n<td style=\"text-align: left; width: 178.864px;\"><strong>OR <span class=\"math inline\">[latex]x\\vee y[\/latex]<\/span><\/strong><\/td>\n<td style=\"text-align: left; width: 180.682px;\"><strong>0<\/strong><\/td>\n<td style=\"text-align: left; width: 126.136px;\">1<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 107.955px;\"><\/td>\n<td style=\"text-align: left; width: 178.864px;\"><strong>0<\/strong><\/td>\n<td style=\"text-align: left; width: 180.682px;\">0<\/td>\n<td style=\"text-align: left; width: 126.136px;\">1<\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 107.955px;\"><\/td>\n<td style=\"text-align: left; width: 178.864px;\"><strong>1<\/strong><\/td>\n<td style=\"text-align: left; width: 180.682px;\">1<\/td>\n<td style=\"text-align: left; width: 126.136px;\">1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"width: 502px;\">\n<caption>Table 1.4: Exclusive disjunction truth table.<\/caption>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 37.9545px;\"><\/td>\n<td style=\"text-align: left; width: 237.955px;\"><\/td>\n<td style=\"text-align: left; width: 133.409px;\"><\/td>\n<td style=\"text-align: left; width: 184.318px;\"><\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 37.9545px;\"><\/td>\n<td style=\"text-align: left; width: 237.955px;\"><strong>XOR <span class=\"math inline\">[latex]x\\oplus y[\/latex]<\/span><\/strong><\/td>\n<td style=\"text-align: left; width: 133.409px;\"><strong>0<\/strong><\/td>\n<td style=\"text-align: left; width: 184.318px;\"><strong>1<\/strong><\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 37.9545px;\"><\/td>\n<td style=\"text-align: left; width: 237.955px;\"><strong>0<\/strong><\/td>\n<td style=\"text-align: left; width: 133.409px;\">0<\/td>\n<td style=\"text-align: left; width: 184.318px;\">1<\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 37.9545px;\"><\/td>\n<td style=\"text-align: left; width: 237.955px;\"><strong>1<\/strong><\/td>\n<td style=\"text-align: left; width: 133.409px;\">1<\/td>\n<td style=\"text-align: left; width: 184.318px;\">0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"width: 472px; height: 55px;\">\n<caption>Table 1.5: Negation truth table.<\/caption>\n<tbody>\n<tr class=\"odd\" style=\"height: 13px;\">\n<td style=\"text-align: left; width: 174.318px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 177.045px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 200.682px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 41.5909px; height: 13px;\"><\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 29px;\">\n<td style=\"text-align: left; width: 174.318px; height: 29px;\"><span class=\"math inline\"><strong>NEG<\/strong> [latex]\\neg x[\/latex]<\/span><\/td>\n<td style=\"text-align: left; width: 177.045px; height: 29px;\"><strong>0<\/strong><\/td>\n<td style=\"text-align: left; width: 200.682px; height: 29px;\"><strong>1<\/strong><\/td>\n<td style=\"text-align: left; width: 41.5909px; height: 29px;\"><\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 13px;\">\n<td style=\"text-align: left; width: 174.318px; height: 13px;\"><\/td>\n<td style=\"text-align: left; width: 177.045px; height: 13px;\">1<\/td>\n<td style=\"text-align: left; width: 200.682px; height: 13px;\">0<\/td>\n<td style=\"text-align: left; width: 41.5909px; height: 13px;\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"hexadecimal-numbers\">Hexadecimal Numbers<\/h2>\n<p>Hexadecimal mode is also positional mode so it works exactly the same way as decimal and binary modes. The base in hexadecimal mode equals to 16 so 16 digits are necessary. First five letters from latin alphabet (A-F) expand standard decimal digits 0-9 making altogether 16 digits. Capital and small letters might be used but should not be mixed in single number. In the table below they are presented with their decimal values:<\/p>\n<table style=\"width: 421px;\">\n<thead>\n<tr class=\"header\">\n<th style=\"text-align: left; width: 216.136px;\">Hexadecimal number<\/th>\n<th style=\"text-align: left; width: 13.4091px;\"><\/th>\n<th style=\"text-align: left; width: 12.5px;\">0<\/th>\n<th style=\"text-align: left; width: 10.6818px;\">1<\/th>\n<th style=\"text-align: left; width: 27.9545px;\">2<\/th>\n<th style=\"text-align: left; width: 17.0455px;\">3<\/th>\n<th style=\"text-align: left; width: 30.6818px;\">4<\/th>\n<th style=\"text-align: left; width: 28.8636px;\">5<\/th>\n<th style=\"text-align: left; width: 28.8636px;\">6<\/th>\n<th style=\"text-align: left; width: 27.0455px;\">7<\/th>\n<th style=\"text-align: left; width: 30.6818px;\">\u2026<\/th>\n<th style=\"text-align: left; width: 36.1364px;\"><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 216.136px;\">Decimal value<\/td>\n<td style=\"text-align: left; width: 14.3182px;\"><\/td>\n<td style=\"text-align: left; width: 13.4091px;\">0<\/td>\n<td style=\"text-align: left; width: 11.5909px;\">1<\/td>\n<td style=\"text-align: left; width: 28.8636px;\">2<\/td>\n<td style=\"text-align: left; width: 17.9545px;\">3<\/td>\n<td style=\"text-align: left; width: 31.5909px;\">4<\/td>\n<td style=\"text-align: left; width: 29.7727px;\">5<\/td>\n<td style=\"text-align: left; width: 29.7727px;\">6<\/td>\n<td style=\"text-align: left; width: 27.9545px;\">7<\/td>\n<td style=\"text-align: left; width: 31.5909px;\">\u2026<\/td>\n<td style=\"text-align: left; width: 37.0455px;\"><\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 216.136px;\">Hexadecimal number<\/td>\n<td style=\"text-align: left; width: 14.3182px;\">\u2026<\/td>\n<td style=\"text-align: left; width: 13.4091px;\">8<\/td>\n<td style=\"text-align: left; width: 11.5909px;\">9<\/td>\n<td style=\"text-align: left; width: 28.8636px;\">A<\/td>\n<td style=\"text-align: left; width: 17.9545px;\">B<\/td>\n<td style=\"text-align: left; width: 31.5909px;\">C<\/td>\n<td style=\"text-align: left; width: 29.7727px;\">D<\/td>\n<td style=\"text-align: left; width: 29.7727px;\">E<\/td>\n<td style=\"text-align: left; width: 27.9545px;\">F<\/td>\n<td style=\"text-align: left; width: 31.5909px;\"><\/td>\n<td style=\"text-align: left; width: 37.0455px;\"><\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 216.136px;\">Decimal value<\/td>\n<td style=\"text-align: left; width: 14.3182px;\">\u2026<\/td>\n<td style=\"text-align: left; width: 13.4091px;\">8<\/td>\n<td style=\"text-align: left; width: 11.5909px;\">9<\/td>\n<td style=\"text-align: left; width: 28.8636px;\">10<\/td>\n<td style=\"text-align: left; width: 17.9545px;\">11<\/td>\n<td style=\"text-align: left; width: 31.5909px;\">12<\/td>\n<td style=\"text-align: left; width: 29.7727px;\">13<\/td>\n<td style=\"text-align: left; width: 29.7727px;\">14<\/td>\n<td style=\"text-align: left; width: 27.9545px;\">15<\/td>\n<td style=\"text-align: left; width: 31.5909px;\"><\/td>\n<td style=\"text-align: left; width: 37.0455px;\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Hexadecimal values are very useful and popular representation of integer numbers, memory addresses and other numbers in programming and computing machinery. One and only one of several suffixes and prefixes should be used to indicate that given number is hexadecimal value. Sometimes suffixes and prefixes are not present as it might be assumed or it is known that given number is hexadecimal. Examples:<\/p>\n<ul>\n<li><strong>0x<\/strong>1245 \u2013 this is hexadecimal number prefixed with \u201c0x\u201d despite no letter is present in the number<\/li>\n<li>3f78<strong>h<\/strong> \u2013 this is hexadecimal number as it is suffixed with \u201ch\u201d letter at the end<\/li>\n<li><strong>$<\/strong>68000 \u2013 dollar sign was used to prefix hexadecimal values on some systems but it is rarely used nowadays as it might be confused with other meanings of the dollar sign in source code<\/li>\n<li>C0DE \u2013 we may guess it is hexadecimal value because typical digits\u2013letters are present<\/li>\n<\/ul>\n<p>Conversion from decimal mode to hexadecimal might be done in the same way as it is done between decimal and binary. In the following example a decimal value 40375 will be converted to its hexadecimal representation:<\/p>\n<p><span class=\"math display\">[latex]\\begin{aligned}  40375 = 16 \\times 2523 + 7 \\\\  2523 = 16 \\times 157 + 11 \\\\  157 = 16 \\times 9 + 13 \\\\  9 = 16 \\times 0 + 9\\end{aligned}[\/latex]<\/span><\/p>\n<p>Remainders are as follows: 7, 11, 13, 9 or when represented as hexadecimal digits they are: 7, B, D, 9. Therefore 40375d = 0x9db7.<\/p>\n<p>Now we try method based on subtractions knowing that <span class=\"math inline\">[latex]16^0=1[\/latex]<\/span>, <span class=\"math inline\">[latex]16^2=256[\/latex]<\/span>, <span class=\"math inline\">[latex]16^3=4096[\/latex]<\/span>. In every step we will look for the biggest value that can be subtracted that is also a product of the base mentioned earlier and term that is lesser or equal to 15 (0xf).<\/p>\n<p><span class=\"math display\">[latex]\\begin{aligned}  40375 - (9 * 4096) &= 3511 \\\\  3511 - (13 * 256) &= 183 \\\\  183 - (11 * 16) &= 7 \\\\  7d - (7 * 1) &= 0 \\end{aligned}[\/latex]<\/span><\/p>\n<h2 id=\"section:integers\">Integers<\/h2>\n<p>The simplest, unsigned integers are simple binary representation of specific value just as it was discussed in section\u00a0<a href=\"#section:binary\" data-reference-type=\"ref\" data-reference=\"section:binary\">1.1<\/a>. Number of possible values and their ranges depends on bits used to represent the number. Characteristic data formats and their corresponding maximum unsigned numbers are shown in table\u00a0<a href=\"#tab:unsignedlimits\" data-reference-type=\"ref\" data-reference=\"tab:unsignedlimits\">1.6<\/a>. Limits of addressable space are theoretical maximums and do not consider caps such as: physical limitations of actual memory modules, hardware limitations of computer mainboard and software implementation introduced by operating systems.<\/p>\n<table style=\"width: 588px; height: 322px;\">\n<caption id=\"tab:unsignedlimits\">Table 1.6: Unsigned integers and their limits in typical data formats.<\/caption>\n<thead>\n<tr class=\"header\" style=\"height: 14px;\">\n<th style=\"text-align: left; width: 153.409px; height: 14px;\">Number of bits<\/th>\n<th style=\"text-align: left; width: 156.136px; height: 14px;\">Maximum unsigned<\/th>\n<th style=\"text-align: left; width: 295.227px; height: 14px;\">Remarks<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">1<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">1<\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Bit<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">4<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">15<\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Half-byte (nibble)<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">8<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">255<\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Byte<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">10<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">1023<\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Typical in ADC<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">12<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">4095<\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Typical in ADC<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">16<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">65535<\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Word; 64 kB addressable<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">32<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\">4294967295<\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Double-word; 4 GB addressable<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">42<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\"><span class=\"math inline\">[latex]2^{42} - 1[\/latex]<\/span><\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">x86_64 Intel CPU addressable space \u2013 4 TB<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">48<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\"><span class=\"math inline\">[latex]2^{48} - 1[\/latex]<\/span><\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">x86_64 AMD CPU addressable space \u2013 256 TB<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 14px;\">\n<td style=\"text-align: left; width: 153.409px; height: 14px;\">64<\/td>\n<td style=\"text-align: left; width: 157.045px; height: 14px;\"><span class=\"math inline\">[latex]2^{64} - 1[\/latex]<\/span><\/td>\n<td style=\"text-align: left; width: 296.136px; height: 14px;\">Quad-word; 16 PB addressable<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"signed-magnitude-integers\">Signed-magnitude Integers<\/h3>\n<p>One bit may be designated to store information about the sign of value. If there is 0 on that bit then value is considered to be positive, otherwise it is negative. Limits of several exemplary data formats are given in table\u00a0<a href=\"#tab:signedlimits\" data-reference-type=\"ref\" data-reference=\"tab:signedlimits\">1.7<\/a>.<\/p>\n<table style=\"width: 547px;\">\n<caption id=\"tab:signedlimits\">Table 1.7: Signed-magnitude integers and their limits in typical data formats.<\/caption>\n<thead>\n<tr class=\"header\">\n<th style=\"text-align: left; width: 132.5px;\">Number of bits<\/th>\n<th style=\"text-align: left; width: 199.773px;\">Limits<\/th>\n<th style=\"text-align: left; width: 272.5px;\">Remarks<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 132.5px;\">4<\/td>\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">[latex]\\pm[\/latex]<\/span>7<\/td>\n<td style=\"text-align: left; width: 273.409px;\">Half-byte (nibble)<\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 132.5px;\">8<\/td>\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">[latex]\\pm[\/latex]<\/span>127<\/td>\n<td style=\"text-align: left; width: 273.409px;\">Byte<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 132.5px;\">10<\/td>\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">[latex]\\pm[\/latex]<\/span>511<\/td>\n<td style=\"text-align: left; width: 273.409px;\">Typical in ADC<\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 132.5px;\">12<\/td>\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">[latex]\\pm[\/latex]<\/span>2047<\/td>\n<td style=\"text-align: left; width: 273.409px;\">Typical in ADC<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 132.5px;\">16<\/td>\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">[latex]\\pm[\/latex]<\/span>32767<\/td>\n<td style=\"text-align: left; width: 273.409px;\">Word<\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 132.5px;\">32<\/td>\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">[latex]\\pm[\/latex]<\/span>2147483647<\/td>\n<td style=\"text-align: left; width: 273.409px;\">Double-word; <span class=\"math inline\">[latex]\\pm[\/latex]<\/span>2 billions<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 132.5px;\">64<\/td>\n<td style=\"text-align: left; width: 200.682px;\"><span class=\"math inline\">[latex]2^{64-1} - 1[\/latex]<\/span><\/td>\n<td style=\"text-align: left; width: 273.409px;\">Quad-word; <span class=\"math inline\">[latex]\\pm[\/latex]<\/span>9 quintillions<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>With signed-magnitude integers there is significant problem of doubled zero as there are two possible values that represent \u201cpositive\u201d (000..00000) and \u201cnegative\u201d (1000..000) zeros. Sum of these two zeros results in \u201cnegative\u201d zero.<\/p>\n<p>Furthermore sum of positive and negative values that have their absolutes equal is not that straightforward. For example lets sum signed-magnitude values of -5 and +5. Assuming that they are stored in 4-bit registers their representations are: 1101 and 0101, where first (most significant) bit represents sign. Direct sum in bit pairwise order starting at the least significant results in 0010 which is <span class=\"math inline\">[latex]+2[\/latex]<\/span> that is not the correct answer.<\/p>\n<p>With signed-magnitude one needs to take sign bit into consideration first. If the bit is the same in both values then they should be added and their sign bit copied. If they have different sign bit then they should be subtracted and bit is copied from the absolutely larger value. This approach is complex and slow thus was superseded by one\u2019s complement and two\u2019s complement representations.<\/p>\n<h3 id=\"ones-complement-and-twos-complement\">One\u2019s Complement and Two\u2019s Complement<\/h3>\n<p>In one\u2019s complement to represent negative number its positive (absolute) binary representation is bitwise inverted with NOT operation. Therefore negative numbers in one\u2019s complement can be recognized by 1 in the most significant bit. So <span class=\"math inline\">[latex]+5[\/latex]<\/span> from previous example is still 0101 but <span class=\"math inline\">[latex]-5[\/latex]<\/span> is 1010. Summing them up results in 1111 that is one of two possible representations of zero. The zero in one\u2019s complement is represented by either 0 on all bits so that it is <span class=\"math inline\">[latex]0^+[\/latex]<\/span> or 1 on all bits so it is <span class=\"math inline\">[latex]0^-[\/latex]<\/span>.<\/p>\n<p>Problem of doubled zero is finally solved in two\u2019s complement. In two\u2019s complement zero has no sign because it is represented only by all bits set to 0.<\/p>\n<p>To convert negative (and only negative!) value from binary to two\u2019s complement one has to simply add one to one\u2019s complement of the value. Therefore <span class=\"math inline\">[latex]+5[\/latex]<\/span> is still <span class=\"math inline\">[latex]0101[\/latex]<\/span> in two\u2019s complement. However, <span class=\"math inline\">[latex]-5[\/latex]<\/span> = 1010 in one\u2019s complement so it is 1011 in two\u2019s complement. If we add these two two\u2019s complement values: 0101 and 1011 the result is <strong>1<\/strong>0000 so it is lengthier than original but in the basis all bits will be equal to zero. This additional bit might be indication of the result equal to zero.<\/p>\n<p>To convert two\u2019s complement that is negative, so one which has the most significant bit set, back to binary representation both previous operations must be performed but in reversed order. So it is necessary to subtract one and invert all bits. For example all \u201cones\u201d (11..11) is a negative value which after subtraction becomes (11..110), and after inversion it is 00..001 so we conclude that it represented <span class=\"math inline\">[latex]-1[\/latex]<\/span> in decimal.<\/p>\n<p>Further examples are given in table\u00a0<a href=\"#tab:twos\" data-reference-type=\"ref\" data-reference=\"tab:twos\">1.8<\/a>. Interesting fact about two\u2019s complement is that this format can represent less positive values than negative values by one.<\/p>\n<p>Two\u2019s complement might look complicated on paper but is not an issue for computing machinery. It is an ultimate solution to all problems discussed above so it is commonly implemented in contemporary processors.<\/p>\n<table style=\"width: 603px; height: 225px;\">\n<caption>Table 1.8: Some exemplary two\u2019s complement values on 8-bit register.<\/caption>\n<thead>\n<tr class=\"header\" style=\"height: 15px;\">\n<th style=\"text-align: left; width: 146.136px; height: 15px;\">Value<\/th>\n<th style=\"text-align: left; width: 472.5px; height: 15px;\">Two\u2019s complement<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+127<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">01111111<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+32<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00100000<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+15<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00001111<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+3<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00000011<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+2<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00000010<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">+1<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00000001<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">0<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">00000000<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-1<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11111111<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-2<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11111110<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-3<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11111101<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-15<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11110001<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-32<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">11100000<\/td>\n<\/tr>\n<tr class=\"odd\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-127<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">10000001<\/td>\n<\/tr>\n<tr class=\"even\" style=\"height: 15px;\">\n<td style=\"text-align: left; width: 146.136px; height: 15px;\">-128<\/td>\n<td style=\"text-align: left; width: 473.409px; height: 15px;\">10000000<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"fixed-point-and-floating-point-numbers\">Fixed-point and Floating-point Numbers<\/h2>\n<p>Electronic circuitry and processors are capable of processing integer numbers quite efficiently. However, real numbers are a problem due to their possible high number of decimal places. The higher number of decimal places the larger is the precision with which the value needs to be stored and so more information it possesses. With increasing precision more bits are needed to store the real value.<\/p>\n<p>There are two approaches to store real numbers in computing machinery: fixed-point and floating-point. First one has limited precision, an arbitrary number of decimal places and so its resolution is limited. Second method provides much higher resolutions and wider range of stored values but introduces an error as it is the best possible approximation with given number of bits used to store the floating point number.<\/p>\n<h3 id=\"fixed-point-numbers\">Fixed-point numbers<\/h3>\n<p>Fixed-point number consists of two parts: integer and fractional. With given size of register some bits are used to store integer part and remaining ones are used to store fractional part. Integer part is stored as it was described in section\u00a0<a href=\"#section:integers\" data-reference-type=\"ref\" data-reference=\"section:integers\">1.3<\/a>. Bits in fractional part have base 2 but their exponents are negative. So there is <span class=\"math inline\">[latex]2^{-1}=\\frac{1}{2}[\/latex]<\/span>, <span class=\"math inline\">[latex]2^{-2}=\\frac{1}{4}[\/latex]<\/span>, <span class=\"math inline\">[latex]2^{-3}=\\frac{1}{8}[\/latex]<\/span>. The series ends on <span class=\"math inline\">[latex]2^{-n}=\\frac{1}{2^n}[\/latex]<\/span>, where <span class=\"math inline\">[latex]n[\/latex]<\/span> cannot be higher than number of bits in used register. Powers of 2 with exponent down to -8 are given in table\u00a0<a href=\"#tab:fractionals\" data-reference-type=\"ref\" data-reference=\"tab:fractionals\">1.9<\/a>.<\/p>\n<table style=\"width: 497px;\">\n<caption>Table 1.9: Start of series of fractional parts in fixed-point mode.<\/caption>\n<thead>\n<tr class=\"header\">\n<th style=\"text-align: left; width: 186.136px;\"><span class=\"math inline\">[latex]n[\/latex]<\/span><\/th>\n<th style=\"text-align: left; width: 432.5px;\"><span class=\"math inline\">[latex]x^n[\/latex]<\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 186.136px;\">-1<\/td>\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">[latex]0.5[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 186.136px;\">-2<\/td>\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">[latex]0.25[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 186.136px;\">-3<\/td>\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">[latex]0.125[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 186.136px;\">-4<\/td>\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">[latex]0.0625[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 186.136px;\">-5<\/td>\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">[latex]0.03125[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 186.136px;\">-6<\/td>\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">[latex]0.015625[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 186.136px;\">-7<\/td>\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">[latex]0.0078125[\/latex]<\/span><\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 186.136px;\">-8<\/td>\n<td style=\"text-align: left; width: 433.409px;\"><span class=\"math inline\">[latex]0.00390625[\/latex]<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Fixed-point is an arbitrary data storage mode as programmers implementing it may choose how many bits should be used per each part. Example below presents fixed-point storage on 8-bit register with 3 bits used to store integer part and 5 to store fractional part. Number that we would like to store in this \u201c<span class=\"math inline\">[latex]3.5[\/latex]<\/span>\u201d format is <span class=\"math inline\">[latex]5.789306640625[\/latex]<\/span>.<\/p>\n<p>Converting decimal 5 to binary results in 101 and these bits will occupy upper part of the register (more significant bits). Now do repetitive subtractions, if they are possible. If subtraction was possible then corresponding fractional bit should be set.<\/p>\n<p><span class=\"math display\">[latex]\\begin{aligned}  0.789306640625 -& 0.5 &=& 0.289306640625 & \\Rightarrow 1 \\\\  0.289306640625 -& 0.25 &=& 0.039306640625 & \\Rightarrow 1 \\\\  0.039306640625 -& 0.125 &<& 0 & \\Rightarrow 0 \\\\  0.039306640625 -& 0.0625 &<& 0 & \\Rightarrow 0 \\\\  0.039306640625 -& 0.03125 &=& 0.008056640625 & \\Rightarrow 1 \\end{aligned}[\/latex]<\/span><\/p>\n<p>So decimal <span class=\"math inline\">[latex]5.789306640625 = 10111001_{3.5}[\/latex]<\/span>. Remainder equals to <span class=\"math inline\">[latex]0.008056640625[\/latex]<\/span> and this is the error introduced due to conversion.<\/p>\n<p>Conversion back is more straightforward: <span class=\"math inline\">[latex]1\\times2^2 + 1\\times2^0 + 1\\times2^{-1} + 1\\times2^{-2} + 1\\times2^{-5} = 5.78125[\/latex]<\/span>. Difference between original value and recovered one equals to remainder that we had to abandon during conversion from decimal to fixed-point.<\/p>\n<h3 id=\"floating-point-numbers\">Floating-point numbers<\/h3>\n<p>Floating-point number can represent highly varying range of values both very large and very small. Contemporary processors provide implementation of IEEE standard\u00a0 that is well established description of floating-point number formats.<\/p>\n<p>Conversion between decimal value and its IEEE\u00a0754 representation is given by equation: <span class=\"math display\">[latex]L_{10} = (-1)^s\\,(1+m)\\,b^{e-x}[\/latex]<\/span><\/p>\n<p>where:<\/p>\n<ul>\n<li><span class=\"math inline\">[latex]L_{10}[\/latex]<\/span> \u2013 decimal value<\/li>\n<li>s \u2013 one bit that represents sign<\/li>\n<li>m \u2013 mantissa that is fractional part<\/li>\n<li>b \u2013 base (radix) that in computer machinery usually is 2<\/li>\n<li>e \u2013 exponent<\/li>\n<li>x \u2013 maximum possible value of exponent (exponent bias) <span class=\"math inline\">[latex]x = 2^k - 2[\/latex]<\/span>, where k is number of exponent bits.<\/li>\n<\/ul>\n<p>Range and precision depend on the number of bits alloted to mantissa and exponent. Some examples are shown in table\u00a0<a href=\"#tab:floatbits\" data-reference-type=\"ref\" data-reference=\"tab:floatbits\">1.10<\/a>. Effective, calculated exponent value E have to be within ranges presented in table\u00a0<a href=\"#tab:floatlimits\" data-reference-type=\"ref\" data-reference=\"tab:floatlimits\">1.11<\/a>.<\/p>\n<table style=\"width: 543px;\">\n<caption>Table 1.10: Some IEEE 754 modes with base 2.<\/caption>\n<thead>\n<tr class=\"header\">\n<th style=\"text-align: left; width: 201.591px;\">Name<\/th>\n<th style=\"text-align: left; width: 112.5px;\">Bits total<\/th>\n<th style=\"text-align: left; width: 113.409px;\">Mantissa bits<\/th>\n<th style=\"text-align: left; width: 163.409px;\">Exponent bits<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 201.591px;\">Half precision<\/td>\n<td style=\"text-align: left; width: 113.409px;\">16<\/td>\n<td style=\"text-align: left; width: 114.318px;\">10<\/td>\n<td style=\"text-align: left; width: 164.318px;\">5<\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 201.591px;\">Single precision<\/td>\n<td style=\"text-align: left; width: 113.409px;\">32<\/td>\n<td style=\"text-align: left; width: 114.318px;\">23<\/td>\n<td style=\"text-align: left; width: 164.318px;\">8<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 201.591px;\">Double precision<\/td>\n<td style=\"text-align: left; width: 113.409px;\">64<\/td>\n<td style=\"text-align: left; width: 114.318px;\">52<\/td>\n<td style=\"text-align: left; width: 164.318px;\">11<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>.<\/p>\n<table style=\"width: 628px;\">\n<caption>Table 1.11: Exponent limits in popular IEEE 754 formats.<\/caption>\n<thead>\n<tr class=\"header\">\n<th style=\"text-align: left; width: 167.045px;\">Name<\/th>\n<th style=\"text-align: left; width: 148.864px;\"><span class=\"math inline\">[latex]e_{max}[\/latex]<\/span><\/th>\n<th style=\"text-align: left; width: 154.318px;\"><span class=\"math inline\">[latex]E_{min}[\/latex]<\/span><\/th>\n<th style=\"text-align: left; width: 120.682px;\"><span class=\"math inline\">[latex]E_{max} = x[\/latex]<\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 167.045px;\">Half precision<\/td>\n<td style=\"text-align: left; width: 149.773px;\">30<\/td>\n<td style=\"text-align: left; width: 155.227px;\">-14<\/td>\n<td style=\"text-align: left; width: 121.591px;\">+15<\/td>\n<\/tr>\n<tr class=\"even\">\n<td style=\"text-align: left; width: 167.045px;\">Single precision<\/td>\n<td style=\"text-align: left; width: 149.773px;\">254<\/td>\n<td style=\"text-align: left; width: 155.227px;\">-126<\/td>\n<td style=\"text-align: left; width: 121.591px;\">+127<\/td>\n<\/tr>\n<tr class=\"odd\">\n<td style=\"text-align: left; width: 167.045px;\">Double precision<\/td>\n<td style=\"text-align: left; width: 149.773px;\">2046<\/td>\n<td style=\"text-align: left; width: 155.227px;\">-1022<\/td>\n<td style=\"text-align: left; width: 121.591px;\">+1023<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Examples in half precision: <span class=\"math display\">[latex]\\begin{aligned}  0\\; & 01111 & 0000000001 & = & (-1)^0 &\\times& 2^{15 - 15} & \\times & (1 + 2^{-10}) &=& 1.0009765625 \\\\  0\\; & 00001 & 1000000001 & = & (-1)^0 &\\times& 2^{1 - 15} & \\times & (1 + 2^{-1} + 2^{-10}) &=& 0.0000916123 \\\\  1\\; & 10001 & 1000000000 & = & (-1)^1 &\\times& 2^{17 - 15} & \\times & (1 + 2^{-1}) &=& -6.0\\end{aligned}[\/latex]<\/span><\/p>\n<p>Examples in single precision: <span class=\"math display\">[latex]\\begin{aligned}  0\\; 01111111 \\; 01000000000000000000000 &= 2^{127 - 127} \\times (1 + 2^{-2}) &= 1.25 \\\\  0\\; 10000010 \\; 11000000000000000000000 &= 2^{130 - 127} \\times (1 + 2^{-1} + 2^{-2}) &= 14.0 \\\\  1\\; 00000001 \\; 00000000000000000000000 &= 2^{1 - 127} \\times 1 &= -1.1755e-38 \\\\  1\\; 11111110 \\; 11111111111111111111111 &\\approx 2^{254 - 127} \\times 2 &= -3.40282e+38 \\\\\\end{aligned}[\/latex]<\/span><\/p>\n<p>If all bits of exponent are set to zero then it is a category of denormalized values. In that situation exponent used in computation has <span class=\"math inline\">[latex]E_{min}[\/latex]<\/span> value as given by table\u00a0<a href=\"#tab:floatlimits\" data-reference-type=\"ref\" data-reference=\"tab:floatlimits\">1.11<\/a>. Mantissa takes form of 0.m instead of regular 1.m hence there is no addition of one to the mantissa. Denormalized values are used to store extremely small numbers. Example of denormalized number: <span class=\"math display\">[latex]\\begin{aligned}  0\\; 00000000 \\; 00000000000000000000001 &= \\\\  2^{-126} \\times (0 + 2^{-23}) &= 1e-45 \\\\\\end{aligned}[\/latex]<\/span><\/p>\n<p>Some other compositions of bits also have special meaning:<\/p>\n<ul>\n<li>+0 \u2013 all bits set to zero<\/li>\n<li>-0 \u2013 all bits set to zero except of sign bit which is set to one<\/li>\n<li>+Infinity \u2013 all exponent bits set to one, e.g.: 0 11111111 00000000000000000000000<\/li>\n<li>-Infinity \u2013 all exponent bits set to one, e.g.: 1 11111111 00000000000000000000000<\/li>\n<li>NaN \u2013 \u201cNot a number\u201d so result of operation such as division by zero is indicated by sign bit set to one, all exponent bits set to one, and at least one of mantissa bits set to one; e.g.: 1 11111111 00000000000000000000001<\/li>\n<\/ul>\n<h2 id=\"endianness\">Endianness<\/h2>\n<p>Data of any kind in computer memory must be stored consistently and orderly. This order is known as endianness. Non-technical people also use endianness when they want to save date, which may have many formats, as for example:<\/p>\n<ul>\n<li>13<sup>th<\/sup> of December, 1981<\/li>\n<li>December 13, 1981<\/li>\n<li>1981-12-13<\/li>\n<\/ul>\n<p>Computer memory might be imagined as a series of data cells. Some microcontrollers enable to access single bits but usually bytes are the smallest units available. Second order data units like words, double-words, quad-words consist of more than one byte and these bytes are stored in computer memory in specific order.<\/p>\n<p>When big-endian is used then with increasing addresses bytes are stored starting from the least significant one (representing smaller values). In little endian it is otherwise so when memory is read byte by byte then data looks like bytes have reversed order. Little endian system is used in x86_64 architecture. These two endiannesses are shown on figure\u00a0<a href=\"#fig:endianness\" data-reference-type=\"ref\" data-reference=\"fig:endianness\">1.1<\/a>.<\/p>\n<figure>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 355px\" class=\"wp-caption aligncenter\"><img class=\"wp-image-38\" src=\"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-content\/uploads\/sites\/16\/2019\/08\/img_5d5128ca31f37.png\" alt=\"\" width=\"355\" height=\"187\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 1.1 Comparison of big-endian and little-endian with one byte unit.<\/figcaption><\/figure><figcaption><\/figcaption><\/figure>\n<p>It is also possible to have different unit than single byte. In such case big-endian storage will have no difference to one shown in figure\u00a0<a href=\"#fig:endianness\" data-reference-type=\"ref\" data-reference=\"fig:endianness\">1.1<\/a>. However, if unit is for example word (two bytes) and 0xd1cec0de is to be stored then in memory it will be present as: 0xc0de, 0xd1ce. If the unit were one byte it would be stored as: 0xde, 0xc0, 0xce, 0xd1.<\/p>\n","protected":false},"author":1,"menu_order":1,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"part":3,"_links":{"self":[{"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/pressbooks\/v2\/chapters\/34"}],"collection":[{"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":14,"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/pressbooks\/v2\/chapters\/34\/revisions"}],"predecessor-version":[{"id":122,"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/pressbooks\/v2\/chapters\/34\/revisions\/122"}],"part":[{"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/pressbooks\/v2\/chapters\/34\/metadata\/"}],"wp:attachment":[{"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/pressbooks\/v2\/chapter-type?post=34"},{"taxonomy":"contributor","embeddable":true,"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/wp\/v2\/contributor?post=34"},{"taxonomy":"license","embeddable":true,"href":"http:\/\/pb.ee.pw.edu.pl\/pb\/microproc\/wp-json\/wp\/v2\/license?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}