- バックアップ一覧
- ソース を表示
- Binary Number Systems は削除されています。
- 1 (2018-06-11 (月) 02:14:53)
- 2 (2018-06-11 (月) 02:40:00)
*3 (2018-06-11 (月) 16:14:40)*- 4 (2018-06-15 (金) 05:38:35)

- 追加された行はこの色です。
- 削除された行はこの色です。

#author("2018-06-11T16:14:40+09:00","","") Binary numbers are representation of amounts using only 0s and 1s, where each digit k of the numbers represent 2^k. For example, the decimal number 20 can be depicted in binary as 10100. *Binary Fractions as Weighted Representations [#ecbae1ca] In the context of computer architecture, fractional numbers are referred to the exponential representation of numbers more precise than the base unit. In other words, each floating point values are expressed as a pair of information about the value of each digits and their corresponding digit numbers. For example, 43.39 in base-10 is expressed as 4*10^1, 3*10^0, 3*10^(-1), 9*10^(-2). Fractional numbers can be interpreted as a weighted expression of each value of each digits. In base-10, weights are referred to the powered tens multiplied onto each digit such as 10^3. Each weight depict how much impact each digit values have on the amount of the represented number. Binary fractions are fractional representations in base-2, and the same principle as the case with base-10 is applied here as well. For example, 10.11 in base-2 is represented as 1*2^1, 0*2^0, 1*2^(-1), 1*2^(-2). [1] *Binary Coded Decimal (BCD) [#w99c25ef] Binary Coded Decimal is a representation of decimal numbers used for converting non binary numbers to binary, where each digit of such numbers are converted to sets of n-bit binary codes. This means that binary representations of each digit values cannot exceed the binary representation of (original base number -1). In the case of decimal numbers, each digit representations cannot exceed 1001, therefore, BCD for decimal numbers should only need 4-bit binary codes for each digits. For example, a decimal number 427 is 0100 0010 0111 in BCD. Since binary (fractional) numbers can be interpreted as simply, weighted representations in binary, It can be said that BCDs for decimal numbers use weights 2^3, 2^2, 2^1, 2^0, or 8, 4, 2, 1. For this reason, BCDs that only require 4-bit binary codes are called 8421 BCD (or simply, BCD). Since BCD to base-n conversion requires each BCD digit representations to not exceed a certain number, during application, BCDs are usually converted to binary and later back to base-n. Such conversions have the advantage of being more efficient than simply converting base-n to binary while having the downside of difficulty in using BCD for other purposes. [2] *Signed Binary Numbers [#qc98d03e] Positive and negative signs in binary codes are represented by adding an additional digit to the code, where 0 is positive and 1 is negative. Signed binary numbers are referred to numbers with such representations. Signed binary numbers consist of two parts: the sign bit, which represents positive or negative states, and the magnitude bits, which represents the magnitude of the number. This means that the disadvantage in which within an n-bit computer, only n-1 bits can be used to depict the amount of the number, is imminent. Another disadvantage can be seen during the depiction of zero, where, during calculation, it is possible that the arithmetic units return either zero with a positive sign or a zero with a negative sign, and represent them as different values even when they are arithmetically the same values. [3] **1’s Complement [#f886446c] 1’s Complement is a signed binary representation in which negative numbers are represented by inverting, or switching all 1s and 0s of, positive signed binary numbers. Such representation allows addition and subtraction of positive and negative numbers to be executed fairly simply as shown below. (Decimal) 5 + (-6) = -1 (1’s Complement) 00101 + 11001 = 1110 (Decimal) 115 - 27 = 88 (1’s Complement) 01110011 + 00011011 = 101010111 For each answer, the existence of a n+1th digit, called overflow, indicates that the value is positive, and the absence indicates otherwise. In order to read the positive answers overflow digit is ignored and a 1 is added to the answer. In the second example, 101010111 is interpreted as 01010111 + 1 = 01011000, or 88 in decimal. [3] **2’s Complement [#q9937ce7] Unlike 1’s Complement representation, 2’s complement depicts negative numbers N of a positive counterpart P with the following equation. N + P = 0 In this case the arithmetics below can be calculated as such. (Decimal) 115 - 27 = 88 (1’s Complement) 01110011 + 11100101 = 101011000 The overflow in 101011000 can be ignored and represented as 01011000. [3] *Sources: [#n5339b89] [1]“Binary Fractions and Fractional Binary Numbers.” Basic Electronics Tutorials, AspenCore Inc., 23 Feb. 2018, www.electronics-tutorials.ws/binary/binary-fractions.html. [2]“Binary Coded Decimal or BCD Numbering System.” Basic Electronics Tutorials, AspenCore Inc., 23 Jan. 2018, www.electronics-tutorials.ws/binary/binary-coded-decimal.html. [3]“Signed Binary Numbers and Two's Complement Used in Binary.” Basic Electronics Tutorials, AspenCore Inc., 28 May 2018, www.electronics-tutorials.ws/binary/signed-binary-numbers.html. *Dicimal-binary conversion function (JavaScript) [#w9629f1a] var val = 0.1; var cnt = -1; var str = "0."; while(cnt > -100){ if(2**cnt < val){ str += 1; val = val - 2**cnt; }else{ str += 0; } cnt--; } console.log(str);