0% found this document useful (0 votes)
15 views13 pages

03.1 Numbers, Binary

Binary numbers represent values using sequences of 0s and 1s, with each digit called a bit. Groups of 8 bits form a byte. Numbers are converted between binary and decimal using algorithms like double-dabble. Signed binary uses the leading bit to indicate positive or negative values. Binary arithmetic performs operations like addition and multiplication using the traditional grade-school algorithms. The modulus operation calculates the remainder when dividing two numbers. Overflow for unsigned integers occurs when the result is too large for the available number of bits.

Uploaded by

Bryan Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

03.1 Numbers, Binary

Binary numbers represent values using sequences of 0s and 1s, with each digit called a bit. Groups of 8 bits form a byte. Numbers are converted between binary and decimal using algorithms like double-dabble. Signed binary uses the leading bit to indicate positive or negative values. Binary arithmetic performs operations like addition and multiplication using the traditional grade-school algorithms. The modulus operation calculates the remainder when dividing two numbers. Overflow for unsigned integers occurs when the result is too large for the available number of bits.

Uploaded by

Bryan Ramirez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Numerical Representation

ECE 3340 – David Mayerich


Binary Numbers
Storing decimal values in registers
Converting binary → decimal and decimal → binary
Binary arithmetic
Binary
• Modern computer systems represent numbers using memory cells
• Individual cells can exist occupy two discrete states: high/low voltage
• Numbers are stored in sequences of memory cells
̶ each cell uses low (0) and high (1) voltage to represent a binary bit
̶ the number of cells constrain the number of values that can be represented
• Each grouping of 8 bits can be used to represent a byte
̶ binary data is generally written in groups of 4-bit units
̶ 4-bits is formally called a nibble – although the term is rarely used

0100 1101 0110 1010 1111 0011


bit byte nibble
Binary
• When discussing numerical calculations
̶ it is convenient to alternate between binary and decimal representations
̶ binary (base-2) values are represented using a 2 subscript: 1101 0110 2
̶ decimal (base-10) values are represented as: 134910
̶ another term for base is radix
̶ a single number in any base is a digit
̶ we will consistently refer to binary (base-2) digits as bits
̶ the term digit will generally be reserved for decimal (base-10) numbers
• Numerical basis is represented by a subscript when the value is
ambiguous:
210 = 102
1011012 = 4510
101.012 = 5.2510
Interpreting binary numbers
• Double-dabble algorithm
̶ initialize a decimal register 𝑥𝑥 = 0
̶ for each digit in the binary number, double 𝑥𝑥 and add the binary value

1101 → 1 1 0 1
𝑥𝑥 = 0
𝑥𝑥 = 2(0) + 1 = 1
𝑥𝑥 = 2(1) + 1 = 3
𝑥𝑥 = 2 3 + 0 = 6
𝑥𝑥 = 2 6 + 1 = 13
Interpreting binary numbers
• Double-dabble algorithm
̶ initialize a decimal register 𝑥𝑥 = 0
̶ for each digit in the binary number, double 𝑥𝑥 and add the binary value

0110 1010 → 0 1 1 0 1 0 1 0
𝑥𝑥 = 0
𝑥𝑥 = 0
𝑥𝑥 = 1 𝑥𝑥 = 6 𝑥𝑥 = 26 𝑥𝑥 = 106
𝑥𝑥 = 3 𝑥𝑥 = 13 𝑥𝑥 = 53
Converting Decimal → Binary
• Remainder method
1) continuously divide a number by 2
2) the binary representation is given by the sequence of remainder values

• Convert 1310 to binary:

0 1
2 1 1
1310 = 11012
2 3 0
2 6 1
2 13
Signed Values
• Mathematical expressions 𝑥𝑥 often take on negative values 𝑥𝑥 < 0
• Consider representing the number:
−1710 = − 0001 0001 2
̶ how could this value be represented in a binary register?
• Sign and magnitude: leading bit represents the sign
̶ 0 indicates a positive (+) value, 1 indicates a negative (−) value

0001 0001 = 1710 1001 0001 = −1710

signed bit signed bit


(+) (−)
Signed Values
• Ones complement: negative values are the bitwise NOT of positive
values:
0001 0001 = 1710 0111 1011 = 12210
1110 1110 = −1710 1000 0100 = −12210

• Twos complement: negative values are the bitwise NOT + 1 of


positive values:
0001 0001 = 1710 0111 1011 = 12210
1110 1110 + 1 1000 0100 + 1
1110 1111 = −1710 1000 0101 = −12210
Fixed-Point Binary
• Fractional values can be represented using binary numbers
1 1 1 1 1 1 1
̶ consecutive decimal places are = = = etc.
2 22 4 23 8 24 16

1101. 1 0 1 1
1) Convert the integer component
1101. 1011
2) Convert the fractional bits 11
13 11 13
16
3) The second set of bits provide the numerator for the fractional
component
Binary Arithmetic
• Arithmetic in any base can be performed using traditional methods:

1101.0011 13.1875 100.01 4.25


+ 11.1001 + 3.5625 x 1.10 x 1.5
10000.1100 16.7500 0 0000 2125
10 001 425
100 01 6.375
110.0110
Modulus Operation
• “x modulo y”: 𝑎𝑎 = 𝑥𝑥 mod 𝑦𝑦
• C/C++: a = x % y;

• Calculates the remainder of x when divided by y using long division

• Examples: 73 mod 7 = 3
13 mod 3 = 1
15 mod 5 = 0
• Common in numerical methods (ex. generating random numbers)
Overflow – unsigned integers
• Overflow: 1111 1111+1=1 0000 0000

8 bits 9 bits
• Overflow behavior is defined for unsigned integer values
1111 1101
+ 0001 0101
1 0001 0010 0001 0010
• This truncation is equivalent to the modulus operation: 𝑥𝑥 mod 2𝑛𝑛
̶ where 𝑛𝑛 is the number of bits in the truncated representation
1111 1101 253
+ 0001 0101 + 21
1 0001 0010 0001 0010 274 mod 28 = 1810 = 0001 0010

You might also like