{"id":1034,"date":"2019-03-11T10:40:52","date_gmt":"2019-03-11T08:40:52","guid":{"rendered":"http:\/\/lab2104.tu-plovdiv.bg\/?p=1034"},"modified":"2024-02-22T02:44:01","modified_gmt":"2024-02-22T00:44:01","slug":"binary-encoding-for-digital-audio","status":"publish","type":"post","link":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/2019\/03\/11\/binary-encoding-for-digital-audio\/","title":{"rendered":"Binary encoding in Digital Audio"},"content":{"rendered":"<h3 style=\"text-align: justify;\">PCM modulation<\/h3>\n<p style=\"text-align: justify;\">In digital audio using pulse-code modulation (PCM), bit depth is the number of bits of information in each sample, and it directly corresponds to the resolution of each sample. Examples of bit depth include Compact Disc Digital Audio, which uses 16 bits per sample, and DVD-Audio and Blu-ray Disc, which can support up to 24 bits per sample. The most common format for binary representation for the samples is 2&#8217;s complement (see the text below).<\/p>\n<h3>Binary representation<\/h3>\n<p style=\"text-align: justify;\">A PCM signal is a sequence of digital audio samples containing the data providing the necessary information to reconstruct the original analog signal. Each sample represents the amplitude of the signal at a specific point in time, and the samples are uniformly spaced in time. The amplitude is the only information explicitly stored in the sample, and it is typically stored as either an integer or a floating point number, encoded as a binary number with a fixed number of digits: the sample&#8217;s bit depth.<\/p>\n<p style=\"text-align: justify;\">The resolution indicates the number of discrete values that can be represented over the range of analog values. The resolution of binary integers increases exponentially as the word length increases. Adding one bit doubles the resolution, adding two quadruples it and so on. The number of possible values that can be represented by an integer bit depth can be calculated by using 2^n, where n is the bit depth. Thus, a 16-bit system has a resolution of 65,536 (2^16) possible values.\u00a0Integer PCM audio data is typically stored as signed numbers in <strong>two&#8217;s complement format<\/strong>.<\/p>\n<p style=\"text-align: justify;\">Many audio file formats and digital audio workstations (DAWs) now support PCM formats with samples represented by floating point numbers. Both the WAV file format and the AIFF file format support floating point representations. Unlike integers, whose bit pattern is a single series of bits, a floating point number is instead composed of separate fields whose mathematical relation forms a number. The most common standard is IEEE 754 which is composed of three fields: a sign bit which represents whether the number is positive or negative, an exponent and a mantissa which is raised by the exponent. The mantissa is expressed as a binary fraction in IEEE base-two floating point formats.<\/p>\n<p style=\"text-align: justify;\">In mathematics, positive numbers (including zero) are represented as unsigned numbers. That is we do not put the +ve sign in front of them to show that they are positive numbers.<\/p>\n<p style=\"text-align: justify;\">However, when dealing with negative numbers we do use a -ve sign in front of the number to show that the number is negative in value and different from a positive unsigned value, and the same is true with <strong>signed binary numbers<\/strong>.<\/p>\n<p style=\"text-align: justify;\">However, in digital circuits there is no provision made to put a plus or even a minus sign to a number, since digital systems operate with binary numbers that are represented in terms of \u201c0\u2019s\u201d and \u201c1\u2019s\u201d. When used together in microelectronics, these \u201c1\u2019s\u201d and \u201c0\u2019s\u201d, called a <b>bit\u00a0<\/b>(being a contraction of <b>BI<\/b>nary digi<b>T<\/b>), fall into several range sizes of numbers which are referred to by common names, such as a <em>byte<\/em> or a <em>word<\/em>.<\/p>\n<p style=\"text-align: justify;\">We have also seen previously that an 8-bit binary number (a byte) can have a value ranging from 0 (00000000<sub>2<\/sub>) to 255 (11111111<sub>2<\/sub>), that is 2<sup>8<\/sup>\u00a0=\u00a0256 different combinations of bits forming a single 8-bit byte. So for example an unsigned binary number such as: 01001101<sub>2<\/sub>\u00a0=\u00a064\u00a0+\u00a08\u00a0+\u00a04\u00a0+\u00a01\u00a0=\u00a077<sub>10<\/sub> in decimal. But Digital Systems and computers must also be able to use and to manipulate negative numbers as well as positive numbers.<\/p>\n<p style=\"text-align: justify;\">Mathematical numbers are generally made up of a sign and a value (magnitude) in which the sign indicates whether the number is positive, (\u00a0<span class=\"ntxt\">+<\/span>\u00a0) or negative, (\u00a0<span class=\"ntxt\">\u2013<\/span>\u00a0) with the value indicating the size of the number, for example 23, +156 or -274. Presenting numbers is this fashion is called \u201csign-magnitude\u201d representation since the left most digit can be used to indicate the sign and the remaining digits the magnitude or value of the number.<\/p>\n<p style=\"text-align: justify;\">Sign-magnitude notation is the simplest and one of the most common methods of representing positive and negative numbers either side of zero, (<span class=\"ntxt\">0<\/span>). Thus negative numbers are obtained simply by changing the sign of the corresponding positive number as each positive or unsigned number will have a signed opposite, for example, +2 and -2, +10 and -10, etc.<\/p>\n<p style=\"text-align: justify;\">But how do we represent signed binary numbers if all we have is a bunch of one\u2019s and zero\u2019s. We know that binary digits, or bits only have two values, either a \u201c1\u201d or a \u201c0\u201d and conveniently for us, a sign also has only two values, being a \u201c<b>+<\/b>\u201d or a \u201c<b>\u2013<\/b>\u201c.<\/p>\n<p style=\"text-align: justify;\">Then we can use a single bit to identify the sign of a <em>signed binary number<\/em> as being positive or negative in value. So to represent a positive binary number (<span class=\"ntxt\">+n<\/span>) and a negative (<span class=\"ntxt\">-n<\/span>) binary number, we can use them with the addition of a sign.<\/p>\n<p style=\"text-align: justify;\">For signed binary numbers the most significant bit (MSB) is used as the sign bit. If the sign bit is \u201c0\u201d, this means the number is positive in value. If the sign bit is \u201c1\u201d, then the number is negative in value. The remaining bits in the number are used to represent the magnitude of the binary number in the usual unsigned binary number format way.<\/p>\n<p style=\"text-align: justify;\">Then we can see that the Sign-and-Magnitude (SM) notation stores positive and negative values by dividing the \u201cn\u201d total bits into two parts: 1 bit for the sign and n\u20131 bits for the value which is a pure binary number. For example, the decimal number 53 can be expressed as an 8-bit signed binary number as follows.<\/p>\n<h3>Positive Signed Binary Numbers<\/h3>\n<p class=\"text-center\"><img decoding=\"async\" src=\"https:\/\/www.electronics-tutorials.ws\/wp-content\/uploads\/2018\/05\/binary-bin7.gif\" alt=\"positive signed binary numbers\" \/><\/p>\n<h3>Negative Signed Binary Numbers<\/h3>\n<p class=\"text-center\"><img decoding=\"async\" src=\"https:\/\/www.electronics-tutorials.ws\/wp-content\/uploads\/2018\/05\/binary-bin8.gif\" alt=\"negative signed binary numbers\" \/><\/p>\n<div class=\"bottomspace\" style=\"text-align: justify;\">The disadvantage here is that whereas before we had a full range <span class=\"ntxt\">n-bit<\/span> unsigned binary number, we now have an <span class=\"ntxt\">n-1 bit<\/span> signed binary number giving a reduced range of digits from:<\/div>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">-2<sup>(n-1)<\/sup>\u00a0\u00a0to\u00a0\u00a0+2<sup>(n-1)<\/sup><\/span><\/p>\n<p style=\"text-align: justify;\">So for example: if we have 4 bits to represent a signed binary number, (1-bit for the <b>Sign bit<\/b>and 3-bits for the <b>Magnitude bits<\/b>), then the actual range of numbers we can represent in sign-magnitude notation would be:<\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">-2<sup>(4-1)<\/sup>\u00a0\u2013\u00a01\u00a0\u00a0\u00a0\u00a0to\u00a0\u00a0\u00a0\u00a0+2<sup>(4-1)<\/sup>\u00a0\u2013\u00a01<\/span><\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">-2<sup>(3)<\/sup>\u00a0\u2013\u00a01\u00a0\u00a0\u00a0\u00a0to\u00a0\u00a0\u00a0\u00a0+2<sup>(3)<\/sup>\u00a0\u2013\u00a01<\/span><\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">-7\u00a0\u00a0\u00a0\u00a0to\u00a0\u00a0\u00a0\u00a0+7<\/span><\/p>\n<p style=\"text-align: justify;\">Whereas before, the range of an unsigned 4-bit binary number would have been from <span class=\"ntxt\">0<\/span> to<span class=\"ntxt\">15<\/span>, or <span class=\"ntxt\">0<\/span> to <span class=\"ntxt\">F<\/span> in hexadecimal, we now have a reduced range of -7 to +7. Thus an unsigned binary number does not have a single sign-bit, and therefore can have a larger binary range as the most significant bit (MSB) is just an extra bit or digit rather than a used sign bit.<\/p>\n<p style=\"text-align: justify;\">Another disadvantage here of the sign-magnitude form is that we can have a positive result for zero, +0 or 0000<sub>2<\/sub>, and a negative result for zero, -0 or 1000<sub>2<\/sub>. Both are valid but which one is correct.<\/p>\n<h2>Signed Binary Numbers Example No1<\/h2>\n<p>Convert the following decimal values into signed binary numbers using the sign-magnitude format:<\/p>\n<table class=\"table2\">\n<tbody>\n<tr>\n<td>-15<sub>10<\/sub>\u00a0\u00a0as a 6-bit number<\/td>\n<td>\u21d2<\/td>\n<td><span class=\"ntxt\">1<\/span><span class=\"mtxt\">01111<sub>2<\/sub><\/span><\/td>\n<\/tr>\n<tr>\n<td>+23<sub>10<\/sub>\u00a0\u00a0as a 6-bit number<\/td>\n<td>\u21d2<\/td>\n<td><span class=\"ntxt\">0<\/span><span class=\"mtxt\">10111<sub>2<\/sub><\/span><\/td>\n<\/tr>\n<tr>\n<td>-56<sub>10<\/sub>\u00a0\u00a0as a 8-bit number<\/td>\n<td>\u21d2<\/td>\n<td><span class=\"ntxt\">1<\/span><span class=\"mtxt\">0111000<sub>2<\/sub><\/span><\/td>\n<\/tr>\n<tr>\n<td>+85<sub>10<\/sub>\u00a0\u00a0as a 8-bit number<\/td>\n<td>\u21d2<\/td>\n<td><span class=\"ntxt\">0<\/span><span class=\"mtxt\">1010101<sub>2<\/sub><\/span><\/td>\n<\/tr>\n<tr>\n<td>-127<sub>10<\/sub>\u00a0\u00a0as a 8-bit number<\/td>\n<td>\u21d2<\/td>\n<td><span class=\"ntxt\">1<\/span><span class=\"mtxt\">1111111<sub>2<\/sub><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"bottomspace\"><\/div>\n<div class=\"bottomspace\">Note that for a 4-bit, 6-bit, 8-bit, 16-bit or 32-bit signed binary number all the bits MUST have a value, therefore \u201c0\u2019s\u201d are used to fill the spaces between the leftmost sign bit and the first or highest value \u201c1\u201d.<\/div>\n<p style=\"text-align: justify;\">The sign-magnitude representation of a binary number is a simple method to use and understand for representing signed binary numbers, as we use this system all the time with normal decimal (base 10) numbers in mathematics. Adding a \u201c1\u201d to the front of it if the binary number is negative and a \u201c0\u201d if it is positive.<\/p>\n<p style=\"text-align: justify;\">However, using this sign-magnitude method can result in the possibility of two different bit patterns having the same binary value. For example, <span class=\"ntxt\">+0<\/span> and <span class=\"ntxt\">-0<\/span> would be <span class=\"ntxt\">0000<\/span> and <span class=\"ntxt\">1000\u00a0<\/span>respectively as a signed 4-bit binary number. So we can see that using this method there can be two representations for zero, a positive zero (\u00a0<span class=\"ntxt\">0<\/span><span class=\"mtxt\">000<sub>2<\/sub><\/span>\u00a0) and also a negative zero (\u00a0<span class=\"ntxt\">1<\/span><span class=\"mtxt\">000<sub>2<\/sub><\/span>\u00a0) which can cause big complications for computers and digital systems.<\/p>\n<h2>One\u2019s Complement of a Signed Binary Number<\/h2>\n<p style=\"text-align: justify;\"><strong>One\u2019s Complement<\/strong> or <strong>1\u2019s Complement<\/strong> as it is also termed, is another method which we can use to represent negative binary numbers in a signed binary number system. In one\u2019s complement, positive numbers (also known as non-complements) remain unchanged as before with the sign-magnitude numbers.<\/p>\n<p style=\"text-align: justify;\">Negative numbers however, are represented by taking the one\u2019s complement (inversion, negation) of the unsigned positive number. Since positive numbers always start with a \u201c0\u201d, the complement will always start with a \u201c1\u201d to indicate a negative number.<\/p>\n<p style=\"text-align: justify;\">The one\u2019s complement of a negative binary number is the complement of its positive counterpart, so to take the one\u2019s complement of a binary number, all we need to do is change each bit in turn. Thus the one\u2019s complement of \u201c1\u201d is \u201c0\u201d and vice versa, then the one\u2019s complement of <span class=\"ntxt\">10010100<sub>2<\/sub><\/span> is simply <span class=\"ntxt\">01101011<sub>2<\/sub><\/span> as all the 1\u2019s are changed to 0\u2019s and the 0\u2019s to 1\u2019s.<\/p>\n<p style=\"text-align: justify;\">The easiest way to find the one\u2019s complement of a signed binary number when building digital arithmetic or logic decoder circuits is to use Inverters. The inverter is naturally a complement generator and can be used in parallel to find the 1\u2019s complement of any binary number as shown.<\/p>\n<h3>1\u2019s Complement Using Inverters<\/h3>\n<p class=\"text-center\"><img decoding=\"async\" src=\"https:\/\/www.electronics-tutorials.ws\/wp-content\/uploads\/2018\/05\/binary-bin9.gif\" alt=\"1's complement using inverters\" \/><\/p>\n<div class=\"bottomspace\" style=\"text-align: justify;\">Then we can see that it is very easy to find the one\u2019s complement of a binary number <span class=\"ntxt\">N<\/span> as all we need do is simply change the 1\u2019s to 0\u2019s and the 0\u2019s to 1\u2019s to give us a <span class=\"ntxt\">-N<\/span> equivalent. Also just like the previous sign-magnitude representation, one\u2019s complement can also have n-bit notation to represent numbers in the range from: <span class=\"ntxt\">-2<sup>(n-1)<\/sup>\u00a0\u00a0<\/span>and<span class=\"ntxt\">\u00a0\u00a0+2<sup>(n-1)<\/sup> \u2013 1<\/span>. For example, a 4-bit representation in the one\u2019s complement format can be used to represent decimal numbers in the range from -7 to +7 with two representations of zero: <span class=\"ntxt\">0000<\/span> (+0) and <span class=\"ntxt\">1111<\/span>(-0) the same as before.<\/div>\n<h2>Addition and Subtraction Using One\u2019s Complement<\/h2>\n<p style=\"text-align: justify;\">One of the main advantages of <strong>One\u2019s Complement<\/strong> is in the addition and subtraction of two binary numbers. In mathematics, subtraction can be implemented in a variety of different ways as <span class=\"ntxt\">A\u00a0\u2013\u00a0B<\/span>, is the same as saying <span class=\"ntxt\">A\u00a0+\u00a0(-B)<\/span> or <span class=\"ntxt\">-B\u00a0+\u00a0A<\/span> etc. Therefore, the complication of subtracting two binary numbers can be performed by simply using addition.<\/p>\n<p style=\"text-align: justify;\">We saw in the Binary Adder tutorial that binary addition follows the same rules as for the normal addition except that in binary there are only two bits (digits) and the largest digit is a \u201c1\u201d, (just as \u201c9\u201d is the largest decimal digit) thus the possible combinations for binary addition are as follows:<\/p>\n<table class=\"table2\">\n<tbody>\n<tr>\n<td><span class=\"mtxt\">0<\/span><\/td>\n<td><span class=\"mtxt\">0<\/span><\/td>\n<td><span class=\"mtxt\">1<\/span><\/td>\n<td><span class=\"mtxt\">1<\/span><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span class=\"mtxt\"><u>+ 0<\/u><\/span><\/td>\n<td><span class=\"mtxt\"><u>+ 1<\/u><\/span><\/td>\n<td><span class=\"mtxt\"><u>+ 0<\/u><\/span><\/td>\n<td><span class=\"mtxt\"><u>+ 1<\/u><\/span><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span class=\"mtxt\">0<\/span><\/td>\n<td><span class=\"mtxt\">1<\/span><\/td>\n<td><span class=\"mtxt\">1<\/span><\/td>\n<td><span class=\"mtxt\">1\u2190\u00a00<\/span><\/td>\n<td>\u00a0( 0 plus a carry 1 )<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"bottomspace\"><\/div>\n<div class=\"bottomspace\" style=\"text-align: justify;\">When the two numbers to be added are both positive, the sum <span class=\"ntxt\">A\u00a0+\u00a0B<\/span>, they can be added together by means of the direct sum (including the number and bit sign), because when single bits are added together, \u201c0 + 0\u201d, \u201c0 + 1\u201d, or \u201c1 + 0\u201d results in a sum of \u201c0\u201d or \u201c1\u201d. This is because when the two bits we want to be added together are odd (\u201c0\u201d + \u201c1\u201d or \u201c1 + 0\u201d), the result is \u201c1\u201d. Likewise when the two bits to be added together are even (\u201c0 + 0\u201d or \u201c1 + 1\u201d) the result is \u201c0\u201d until you get to \u201c1 + 1\u201d then the sum is equal to \u201c0\u201d plus a carry \u201c1\u201d. Let\u2019s look at a simple example.<\/div>\n<h2>Subtraction of Two Binary Numbers<\/h2>\n<p style=\"text-align: justify;\">An 8-bit digital system is required to subtract the following two numbers 115 and 27 from each other using one\u2019s complement. So in decimal this would be: <span class=\"ntxt\">115\u00a0\u2013\u00a027\u00a0=\u00a088<\/span>.<\/p>\n<p style=\"text-align: justify;\">First we need to convert the two decimal numbers into binary and make sure that each number has the same number of bits by adding leading zero\u2019s to produce an 8-bit number (byte). Therefore:<\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">115<sub>10<\/sub><\/span>\u00a0\u00a0in binary is:\u00a0\u00a0<span class=\"mtxt\">01110011<sub>2<\/sub><\/span><\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">27<sub>10<\/sub><\/span>\u00a0\u00a0\u00a0in binary is:\u00a0\u00a0<span class=\"mtxt\">00011011<sub>2<\/sub><\/span><\/p>\n<p style=\"text-align: justify;\">Now we need to find the complement of the second binary number, (<span class=\"ntxt\">00011011<\/span>) while leaving the first number (<span class=\"ntxt\">01110011<\/span>) unchanged. So by changing all the 1\u2019s to 0\u2019s and 0\u2019s to 1\u2019s, the one\u2019s complement of <span class=\"ntxt\">00011011<\/span> is therefore equal to <span class=\"ntxt\">11100100<\/span>.<\/p>\n<p style=\"text-align: justify;\">Adding the first number and the complement of the second number gives:<\/p>\n<table class=\"table2\">\n<tbody>\n<tr>\n<td><span class=\"mtxt\">01110011<\/span><\/td>\n<\/tr>\n<tr>\n<td>+\u00a0<span class=\"mtxt\">11100100<\/span><\/td>\n<\/tr>\n<tr>\n<td>Overflow\u00a0\u2192\u00a0<span class=\"mtxt\"><b>1<\/b><\/span>\u00a0<span class=\"mtxt\">01010111<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"bottomspace\"><\/div>\n<div class=\"bottomspace\" style=\"text-align: justify;\">Since the digital system is to work with 8-bits, only the first eight digits are used to provide the answer to the sum, and we simply ignore the last bit (bit 9). This bit is call an \u201coverflow\u201d bit. Overflow occurs when the sum of the most significant (left-most) column produces a carry forward. This overflow or carry bit can be ignored completely or passed to the next digital section for use in its calculations. Overflow indicates that the answer is positive. If there is no overflow then the answer is negative.<\/div>\n<p style=\"text-align: justify;\">The 8-bit result from above is: <span class=\"mtxt\">01010111<\/span> (the overflow \u201c1\u201d cancels out) and to convert it back from a one\u2019s complement answer to the real answer we now have to add \u201c1\u201d to the one\u2019s complement result, therefore:<\/p>\n<table class=\"table2\">\n<tbody>\n<tr>\n<td><span class=\"mtxt\">01010111<\/span><\/td>\n<\/tr>\n<tr>\n<td>+\u00a0<span class=\"mtxt\">1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span class=\"mtxt\">01011000<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"bottomspace\"><\/div>\n<div class=\"bottomspace\" style=\"text-align: justify;\">So the result of subtracting 27 ( <span class=\"mtxt\">00011011<sub>2<\/sub><\/span> ) from 115 ( <span class=\"mtxt\">01110011<sub>2<\/sub><\/span> ) using 1\u2019s complement in binary gives the answer of: <span class=\"mtxt\">01011000<sub>2<\/sub><\/span> or (64 + 16 + 8) = 88<sub>10<\/sub> in decimal.<\/div>\n<p style=\"text-align: justify;\">Then we can see that signed or unsigned binary numbers can be subtracted from each other using <strong>One\u2019s Complement<\/strong> and the process of addition. Binary adders such as the TTL 74LS83 or 74LS283 can be used to add or subtract two 4-bit signed binary numbers or cascaded together to produce 8-bit adders complete with carry-out.<\/p>\n<h2>Two\u2019s Complement of a Signed Binary Number<\/h2>\n<p style=\"text-align: justify;\"><strong>Two\u2019s Complement<\/strong> or <strong>2\u2019s Complement<\/strong> as it is also termed, is another method like the previous sign-magnitude and one\u2019s complement form, which we can use to represent negative binary numbers in a signed binary number system. In two\u2019s complement, the positive numbers are exactly the same as before for unsigned binary numbers. A negative number, however, is represented by a binary number, which when added to its corresponding positive equivalent results in zero.<\/p>\n<p style=\"text-align: justify;\">In two\u2019s complement form, a negative number is the 2\u2019s complement of its positive number with the subtraction of two numbers being <span class=\"ntxt\">A\u00a0\u2013\u00a0B\u00a0=\u00a0A\u00a0+\u00a0( 2\u2019s complement of B )<\/span> using much the same process as before as basically, two\u2019s complement is one\u2019s complement + 1.<\/p>\n<p style=\"text-align: justify;\">The main advantage of two\u2019s complement over the previous one\u2019s complement is that there is no double-zero problem plus it is a lot easier to generate the two\u2019s complement of a signed binary number. Therefore, arithmetic operations are relatively easier to perform when the numbers are represented in the two\u2019s complement format.<\/p>\n<p style=\"text-align: justify;\">Let\u2019s look at the subtraction of our two 8-bit numbers 115 and 27 from above using two\u2019s complement, and we remember from above that the binary equivalents are:<\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">115<sub>10<\/sub><\/span>\u00a0\u00a0in binary is:\u00a0\u00a0<span class=\"mtxt\">01110011<sub>2<\/sub><\/span><\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">27<sub>10<\/sub><\/span>\u00a0\u00a0\u00a0in binary is:\u00a0\u00a0<span class=\"mtxt\">00011011<sub>2<\/sub><\/span><\/p>\n<p style=\"text-align: justify;\">Our numbers are 8-bits long, then there are 2<sup>8<\/sup> digits available to represent our values and in binary this equals: <span class=\"mtxt\">100000000<sub>2<\/sub><\/span> or <span class=\"ntxt\">256<sub>10<\/sub><\/span>. Then the two\u2019s complement of 27<sub>10<\/sub> will be:<\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">(2<sup>8<\/sup>)<sub>2<\/sub>\u00a0\u2013\u00a000011011\u00a0=\u00a0100000000\u00a0\u2013\u00a000011011\u00a0=\u00a011100101<sub>2<\/sub><\/span><\/p>\n<p style=\"text-align: justify;\">The complementation of the second negative number means that the subtraction becomes a much easier addition of the two numbers so therefore the sum is: <span class=\"ntxt\">115\u00a0+\u00a0( 2\u2019s complement of 27 )<\/span> which is:<\/p>\n<p class=\"text-center\" style=\"text-align: justify;\"><span class=\"mtxt\">01110011\u00a0+\u00a011100101\u00a0=\u00a0<\/span><span class=\"ntxt\"><b>1<\/b><\/span>\u00a0<span class=\"mtxt\">01011000<sub>2<\/sub><\/span><\/p>\n<p style=\"text-align: justify;\">As previously, the 9th overflow bit is disregarded as we are only interested in the first 8-bits, so the result is: <span class=\"mtxt\">01011000<sub>2<\/sub><\/span> or (64 + 16 + 8) = 88<sub>10<\/sub> in decimal the same as before.<\/p>\n<h2>Signed Binary Numbers Summary<\/h2>\n<p style=\"text-align: justify;\">We have seen that negative binary numbers can be represented by using the most significant bit (MSB) as a sign bit. If an <span class=\"ntxt\">n bit<\/span> binary number is signed the leftmost bit is used to represent the sign leaving <span class=\"ntxt\">n-1 bits<\/span> to represent the number.<\/p>\n<p style=\"text-align: justify;\">For example, in a 4-bit binary number, this leaves only 3 bits to hold the actual number. If however, the binary number is unsigned then all the bits can be used to represent the number.<\/p>\n<p style=\"text-align: justify;\">The representation of a signed binary number is commonly referred to as the <em>sign-magnitude notation<\/em> and if the sign bit is \u201c0\u201d, the number is positive. If the sign bit is \u201c1\u201d, then the number is negative. When dealing with binary arithmetic operations, it is more convenient to use the complement of the negative number.<\/p>\n<p style=\"text-align: justify;\">Complementation is an alternative way of representing negative binary numbers. This alternative coding system allows for the subtraction of negative numbers by using simple addition.<\/p>\n<p style=\"text-align: justify;\">Since positive sign-magnitude numbers always start with a zero (0), its complement will therefore always start with a one (1) to indicate a negative number as shown in the following table.<\/p>\n<h3>4-bit Signed Binary Number Comparison<\/h3>\n<table class=\"table1\">\n<tbody>\n<tr>\n<td>Decimal<\/td>\n<td>Signed Magnitude<\/td>\n<td>Signed One\u2019s Complement<\/td>\n<td>Signed Two\u2019s Complement<\/td>\n<\/tr>\n<tr>\n<td>+7<\/td>\n<td>0111<\/td>\n<td>0111<\/td>\n<td>0111<\/td>\n<\/tr>\n<tr>\n<td>+6<\/td>\n<td>0110<\/td>\n<td>0110<\/td>\n<td>0110<\/td>\n<\/tr>\n<tr>\n<td>+5<\/td>\n<td>0101<\/td>\n<td>0101<\/td>\n<td>0101<\/td>\n<\/tr>\n<tr>\n<td>+4<\/td>\n<td>0100<\/td>\n<td>0100<\/td>\n<td>0100<\/td>\n<\/tr>\n<tr>\n<td>+3<\/td>\n<td>0011<\/td>\n<td>0011<\/td>\n<td>0011<\/td>\n<\/tr>\n<tr>\n<td>+2<\/td>\n<td>0010<\/td>\n<td>0010<\/td>\n<td>0010<\/td>\n<\/tr>\n<tr>\n<td>+1<\/td>\n<td>0001<\/td>\n<td>0001<\/td>\n<td>0001<\/td>\n<\/tr>\n<tr>\n<td>+0<\/td>\n<td>0000<\/td>\n<td>0000<\/td>\n<td>0000<\/td>\n<\/tr>\n<tr>\n<td>-0<\/td>\n<td>1000<\/td>\n<td>1111<\/td>\n<td>\u2013<\/td>\n<\/tr>\n<tr>\n<td>-1<\/td>\n<td>1001<\/td>\n<td>1110<\/td>\n<td>1111<\/td>\n<\/tr>\n<tr>\n<td>-2<\/td>\n<td>1010<\/td>\n<td>1101<\/td>\n<td>1110<\/td>\n<\/tr>\n<tr>\n<td>-3<\/td>\n<td>1011<\/td>\n<td>1100<\/td>\n<td>1101<\/td>\n<\/tr>\n<tr>\n<td>-4<\/td>\n<td>1100<\/td>\n<td>1011<\/td>\n<td>1100<\/td>\n<\/tr>\n<tr>\n<td>-5<\/td>\n<td>1101<\/td>\n<td>1010<\/td>\n<td>1011<\/td>\n<\/tr>\n<tr>\n<td>-6<\/td>\n<td>1110<\/td>\n<td>1001<\/td>\n<td>1010<\/td>\n<\/tr>\n<tr>\n<td>-7<\/td>\n<td>1111<\/td>\n<td>1000<\/td>\n<td>1001<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"bottomspace\" style=\"text-align: justify;\"><\/div>\n<div class=\"bottomspace\" style=\"text-align: justify;\">Signed-complement forms of binary numbers can use either 1\u2019s complement or 2\u2019s complement. The 1\u2019s complement and the 2\u2019s complement of a binary number are important because they permit the representation of negative numbers.<\/div>\n<p style=\"text-align: justify;\">The method of 2\u2019s complement arithmetic is commonly used in computers to handle negative numbers the only disadvantage is that if we want to represent negative binary numbers in the signed binary number format, we must give up some of the range of the positive number we had before.<\/p>\n<h3 style=\"text-align: justify;\">Some errors in the designs of DACs<\/h3>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/lab2104.tu-plovdiv.bg\/wp-content\/uploads\/2019\/03\/1541_inv.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-1048\" src=\"https:\/\/lab2104.tu-plovdiv.bg\/wp-content\/uploads\/2019\/03\/1541_inv-300x224.jpg\" alt=\"1541_inv\" width=\"300\" height=\"224\" srcset=\"https:\/\/lab2104.tu-plovdiv.bg\/wp-content\/uploads\/2019\/03\/1541_inv-300x224.jpg 300w, https:\/\/lab2104.tu-plovdiv.bg\/wp-content\/uploads\/2019\/03\/1541_inv.jpg 311w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>There exist a lot of &#8216;improved&#8217; designs for audio DACs. For example the common used idea is to make the dual DAC balanced. That means it will not work as one stereo DAC but will be used for one channel only with XLR balanced outputs. This approach require the data for the one of the internal DAC to be inverted and the common way is to use inverters. Yes it will work but mathematically it will cause a some small distortion as the input signal is 2&#8217;s complemented and it cannot be inverse just by using inverters just like 1&#8217;s complemented signal. The right way to do the inversion is by adding &#8216;1&#8217;\u00a0to the inverse digit, which is not so easy to do because it will require external shift registers, lathes and adders.<\/p>\n<p style=\"text-align: justify;\">Apparently many DACs that use I2S architecture (and related chipsets) do not correctly convert 16 bit samples to 24 or 32 bit words prior to conversion.\u00a0LSB extension error under I2S: this problem started out during the transition from 32 FS (16 bit) to 64 FS clocking to accommodate sample lengths above 16 bits. Under the I2S spec, the LSB extension of a 16 bit sample to 24 or 32 bits is accomplished by simply adding bits set to zero. Seems reasonable by itself.\u00a0However, the samples are represented internally in 2&#8217;s complement format, so in the case of positive numbers, one should extend the word length by adding the MSB (0) to the tail, and for negative numbers, adding the MSB (1) to the tail.\u00a0Thus, 50% of the time, namely for the negative samples as represented in 2&#8217;s complement mode, the I2S convention is incorrectly forcing the LSBs to be 0, which introduces an error or distortion.\u00a0Some examples for a 16 to 32 bit extension (MSB on the left):<\/p>\n<p style=\"text-align: justify;\">Full scale sample:<\/p>\n<p style=\"text-align: justify;\">1111 1111 1111 1111 under I2S becomes 1111 1111 1111 1111 0000 0000 0000 0000<br \/>\n1111 1111 1111 1111 in correct 2s comp 1111 1111 1111 1111 1111 1111 1111 1111<\/p>\n<p style=\"text-align: justify;\">This error (the 16 LSBs set to 0 instead of 1) gives a distortion of 0.0015% of roughly -96 dB. (subtract incorrectly formatted sample from correctly formatted sample, divided by the correctly formatted sample).<\/p>\n<p style=\"text-align: justify;\">For somewhat less than full scale sample:<\/p>\n<p style=\"text-align: justify;\">1000 1111 1111 1111 under I2S becomes 1010 1111 1111 1111 0000 0000 0000 0000<br \/>\n1000 1111 1111 1111 in correct 2s comp 1000 1111 1111 1111 1111 1111 1111 1111<\/p>\n<p style=\"text-align: justify;\">This time the error is about -66 dB.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PCM modulation In digital audio using pulse-code modulation (PCM), bit depth is the number of bits of information in each sample, and it directly corresponds to the resolution of each sample. Examples of bit depth include Compact Disc Digital Audio, which uses 16 bits per sample, and DVD-Audio and Blu-ray Disc, which can support up [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/posts\/1034"}],"collection":[{"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/comments?post=1034"}],"version-history":[{"count":30,"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/posts\/1034\/revisions"}],"predecessor-version":[{"id":1158,"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/posts\/1034\/revisions\/1158"}],"wp:attachment":[{"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/media?parent=1034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/categories?post=1034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lab2104.tu-plovdiv.bg\/index.php\/wp-json\/wp\/v2\/tags?post=1034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}