Podcast
Questions and Answers
What are computer systems fundamentally based on?
What are computer systems fundamentally based on?
Why is the binary system preferred over other bases for electronic implementation?
Why is the binary system preferred over other bases for electronic implementation?
What does a bit vector represent?
What does a bit vector represent?
How is the numeric value of a binary number calculated?
How is the numeric value of a binary number calculated?
Signup and view all the answers
What is the correct prefix for a binary number in written form?
What is the correct prefix for a binary number in written form?
Signup and view all the answers
What role do bits play in computer systems?
What role do bits play in computer systems?
Signup and view all the answers
What type of signals do binary systems represent?
What type of signals do binary systems represent?
Signup and view all the answers
What is the significance of the rightmost digit in a decimal number?
What is the significance of the rightmost digit in a decimal number?
Signup and view all the answers
What is the decimal equivalent of the hexadecimal number 1D8A?
What is the decimal equivalent of the hexadecimal number 1D8A?
Signup and view all the answers
Which of the following correctly describes the process of converting binary to hexadecimal?
Which of the following correctly describes the process of converting binary to hexadecimal?
Signup and view all the answers
Which logic gate outputs a high signal only if at least one input signal is high?
Which logic gate outputs a high signal only if at least one input signal is high?
Signup and view all the answers
What is the output of an AND gate given the inputs 1 and 0?
What is the output of an AND gate given the inputs 1 and 0?
Signup and view all the answers
In Boolean algebra, what is the output of the XOR gate when both inputs are 0?
In Boolean algebra, what is the output of the XOR gate when both inputs are 0?
Signup and view all the answers
If the binary number 10010 is converted to hexadecimal, what is the result?
If the binary number 10010 is converted to hexadecimal, what is the result?
Signup and view all the answers
What is the correct hexadecimal representation of the decimal number 255?
What is the correct hexadecimal representation of the decimal number 255?
Signup and view all the answers
Which operation does NOT belong to the common logical operations represented in Boolean algebra?
Which operation does NOT belong to the common logical operations represented in Boolean algebra?
Signup and view all the answers
What is the correct way to denote the hexadecimal number FA1D37B?
What is the correct way to denote the hexadecimal number FA1D37B?
Signup and view all the answers
How many bits does one hexadecimal digit represent?
How many bits does one hexadecimal digit represent?
Signup and view all the answers
Which of the following is the decimal value for the hexadecimal number 1D8A?
Which of the following is the decimal value for the hexadecimal number 1D8A?
Signup and view all the answers
In binary, what does the number 13 convert to?
In binary, what does the number 13 convert to?
Signup and view all the answers
What is the range of values representable in a single byte in hexadecimal?
What is the range of values representable in a single byte in hexadecimal?
Signup and view all the answers
What is the first step in converting a decimal number to hexadecimal?
What is the first step in converting a decimal number to hexadecimal?
Signup and view all the answers
What is the hexadecimal equivalent of the binary number 1011 0001 0010 1111?
What is the hexadecimal equivalent of the binary number 1011 0001 0010 1111?
Signup and view all the answers
What is the quotient when converting the decimal number 7562 to hexadecimal using the division method?
What is the quotient when converting the decimal number 7562 to hexadecimal using the division method?
Signup and view all the answers
What condition leads to a negative overflow when adding two w-bit signed numbers?
What condition leads to a negative overflow when adding two w-bit signed numbers?
Signup and view all the answers
What is the maximum possible value of an unsigned multiplication result for w-bit numbers?
What is the maximum possible value of an unsigned multiplication result for w-bit numbers?
Signup and view all the answers
What happens to the high order bits during the multiplication of signed and unsigned bit vectors?
What happens to the high order bits during the multiplication of signed and unsigned bit vectors?
Signup and view all the answers
Which operation is equivalent to multiplying a number by a power of 2?
Which operation is equivalent to multiplying a number by a power of 2?
Signup and view all the answers
What is the smallest possible value for a two's complement product of w-bit numbers?
What is the smallest possible value for a two's complement product of w-bit numbers?
Signup and view all the answers
What is the result of converting a w-bit signed integer X to a (w+k)-bit integer X' using sign extension?
What is the result of converting a w-bit signed integer X to a (w+k)-bit integer X' using sign extension?
Signup and view all the answers
What happens to the value when a 32-bit integer is truncated to a 16-bit short?
What happens to the value when a 32-bit integer is truncated to a 16-bit short?
Signup and view all the answers
What is the negation of a bit-vector X represented by the equation -X = ~X + 1?
What is the negation of a bit-vector X represented by the equation -X = ~X + 1?
Signup and view all the answers
In the addition of signed numbers, why is the true sum often disregarded?
In the addition of signed numbers, why is the true sum often disregarded?
Signup and view all the answers
When performing modular addition on unsigned numbers, how are overflow bits treated?
When performing modular addition on unsigned numbers, how are overflow bits treated?
Signup and view all the answers
What is the result of the operation 01101 + 11011 in modular arithmetic?
What is the result of the operation 01101 + 11011 in modular arithmetic?
Signup and view all the answers
What is the implication of performing operations on signed integers regarding the sign bit?
What is the implication of performing operations on signed integers regarding the sign bit?
Signup and view all the answers
What does the operation ~X + X yield for any signed integer X?
What does the operation ~X + X yield for any signed integer X?
Signup and view all the answers
Study Notes
Intro to Hexadecimal
- Base 16
- Requires 16 symbols, 0..9 + A,B,C,D,E,F
- Shorthand notation for binary
- Written in C as 0xFA1D37B or 0xfa1d37b
Advantage of Hexadecimal
- Easy to convert between hexadecimal and binary since one hex digit represents four bits
- Example: 1011000100101111 = 1011 0001 0010 1111 = B 1 2 F = 0xB12F
Bytes
- One byte equals 8 bits
- Range of values in binary: 000000002 to 111111112
- Range of values in decimal: 010 to 25510
- Range of values in hexadecimal: 0016 to FF16
Data Sizes
- Kilo, Mega, Giga prefixes can be confusing because they are used in both binary and decimal systems
- This course uses the binary sense of Kilo, Mega, Giga etc.
Conversions
- Every four binary digits convert to one hex digit and vice versa.
- Example: 11001101 = 1100 1101 = CD
Boolean Algebra Truth Tables
- AND:
- 0 & 0 = 0
- 0 & 1 = 0
- 1 & 0 = 0
- 1 & 1 = 1
- OR:
- 0 | 0 = 0
- 0 | 1 = 1
- 1 | 0 = 1
- 1 | 1 = 1
- NOT (Complement):
- ~0 = 1
- ~1 = 0
- XOR:
- 0 ^ 0 = 0
- 0 ^ 1 = 1
- 1 ^ 0 = 1
- 1 ^ 1 = 0
Logic Circuits
- Logic gates perform specific logic operations
- They are the building blocks of digital circuits
- OR gate has two or more inputs and one output
- The output is high if any or all inputs are high
Bits
- Computers are binary machines
- Bits are represented as 0 and 1
- Everything on a computer is encoded as a set of bits, including programs and data
Why Bits?
- Electronic implementation is easier using bi-stable elements
- Bits are more reliable to transmit on noisy and inaccurate wires
Bit Vector
- A bit vector is a sequence of bits, but its meaning depends on the type of information it represents and the encoding used.
- Without context, a bit vector has no inherent meaning.
Converting Binary to Decimal
- Sum the value of each binary digit times its power of 2.
- Example: 11001 = 1 * 24 + 1 * 23 + 0 * 22 + 0 * 21 + 1 * 20 = 25
Converting Decimal to Binary
- Divide the number by 2
- The remainder of each division becomes the binary digit
- Repeat until the quotient is 0
- Example: 13 = 1101
- 13 / 2 = 6 (remainder 1)
- 6 / 2 = 3 (remainder 0)
- 3 / 2 = 1 (remainder 1)
- 1 / 2 = 0 (remainder 1)
Converting Decimal to Hexadecimal
- Divide the number by 16
- The remainder of each division becomes the hex digit
- Repeat until the quotient is 0
- Example: 7562 = 1D8A
- 7562 / 16 = 472 (remainder 10 = A)
- 472 / 16 = 29 (remainder 8)
- 29 / 16 = 1 (remainder 13 = D)
- 1 / 16 = 0 (remainder 1)
Converting Hexadecimal to Decimal
- Multiply each hexadecimal digit by its corresponding power of 16.
- Sum the results.
- Example: 1D8A = (1 × 16³) + (13 × 16²) + (8 × 16¹) + (10 × 16⁰) = 7562
Negation
- To compute -X for a bit-vector X, compute the complement and add 1: -X = ~X + 1.
- Example: X = 011001 = 25, ~X = 100110 = -26, ~X+1 = 100111 = -25
Addition for Unsigned Numbers
- Standard addition function ignores carry bits and implements modular arithmetic.
- Formula: UAdd(u , v) = (u + v) mod 2w
Addition of Signed Numbers
- True sum requires w+1 bits
- Addition ignores the carry bit
- If TAddw(u, v) >= 2w–1, then sum becomes negative (positive overflow)
- If TAddw(u, v) < –2w–1, then sum becomes positive (negative overflow)
Multiplication
- Task: Computing Exact Product of w-bit numbers x, y (either signed or unsigned)
- Ranges of results:
- Unsigned multiplication requires up to 2w bits to store result: 0 ≤ x * y ≤ (2w – 1)2 = 22w – 2w+1 + 1
- Two's complement smallest possible value requires up to 2w-1 bits: x * y ≥ (–2w–1)*(2w–1–1)= –22w–2 + 2w–1
- Two's complement largest possible value requires up to 2w bits (in one case): x * y ≤ (–2w–1)2 = 22w–2
- Maintaining exact results would need to keep expanding the word size with each product computed.
Multiplication by Power of 2 (Left Shift)
- Multiplication by a power of two is equivalent to the left shift operation.
- Example: u * 2k is the same as u << k
Sign Extension
- Task: Given a w-bit signed integer X, convert it to a (w+k)-bit integer X' with the same value.
- Solution: Make k copies of the sign bit.
- Example: X = xw-1 xw-2...x1x0, X' = xw-1...xw-1xw-1 xw-2...x1x0
- C automatically performs sign extension when converting from a smaller data type to a larger one.
Truncating
- Example: From int to short (from 32-bit to 16-bit)
- High-order bits are truncated, altering the value
- This non-intuitive behavior can lead to bugs in code.
- Example:
int i = 1572539; short si = (short) i; printf(" i = %i\n si = %i\n\n ", i, si );
- This prints:
i = 1572539 si = -325
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz covers the basics of hexadecimal notation and its advantages over binary representation. It includes concepts like byte size, data conversions, and Boolean algebra truth tables. Perfect for students learning about number systems in programming.