Podcast
Questions and Answers
Which of the following is the most basic unit of information in modern computing?
Which of the following is the most basic unit of information in modern computing?
- Bit
- Byte
- Paragraph (correct)
- Word
Bytes are always 8 bits in size, regardless of the system architecture.
Bytes are always 8 bits in size, regardless of the system architecture.
False (B)
What is the typical size, in bytes, of a 'page' in memory?
What is the typical size, in bytes, of a 'page' in memory?
4096
A string of n characters, terminated by a null character, requires ______ bytes of storage.
A string of n characters, terminated by a null character, requires ______ bytes of storage.
Match the following units of information with their typical sizes:
Match the following units of information with their typical sizes:
Which of the following is NOT a reason why hexadecimal is used?
Which of the following is NOT a reason why hexadecimal is used?
In 'Big Endian' byte ordering, bytes are ordered from least significant to most significant.
In 'Big Endian' byte ordering, bytes are ordered from least significant to most significant.
What prefix is commonly used to denote a hexadecimal representation?
What prefix is commonly used to denote a hexadecimal representation?
The American Standard Code for Information Interchange is more commonly known as ______.
The American Standard Code for Information Interchange is more commonly known as ______.
Match the bitwise operator with its description:
Match the bitwise operator with its description:
Why is it important to know the byte ordering (Endianness) when exchanging data between systems?
Why is it important to know the byte ordering (Endianness) when exchanging data between systems?
ASCII can encode characters from all known languages.
ASCII can encode characters from all known languages.
How many hexadecimal digits are needed to represent a single byte?
How many hexadecimal digits are needed to represent a single byte?
To convert a decimal value to hexadecimal, you repeatedly ______ the decimal value by 16.
To convert a decimal value to hexadecimal, you repeatedly ______ the decimal value by 16.
Match the following number systems with their bases:
Match the following number systems with their bases:
What is a 'word' in the context of computer architecture?
What is a 'word' in the context of computer architecture?
Addresses of bytes in memory are always decreasing.
Addresses of bytes in memory are always decreasing.
In C, what data type is typically used to represent a byte?
In C, what data type is typically used to represent a byte?
Each byte in physical memory has a unique ______.
Each byte in physical memory has a unique ______.
Match the following values to their bitwise complement (using ~ operator):
Match the following values to their bitwise complement (using ~ operator):
If x = 0xD5
(11010101 in binary) and y = 0x5D
(01011101 in binary), what is the result of x & y
(bitwise AND)?
If x = 0xD5
(11010101 in binary) and y = 0x5D
(01011101 in binary), what is the result of x & y
(bitwise AND)?
A bitwise OR operation will always result in a value that is less than or equal to either of the operands.
A bitwise OR operation will always result in a value that is less than or equal to either of the operands.
What is the primary difference between ASCII and Unicode?
What is the primary difference between ASCII and Unicode?
In the function int test(unsigned char b, int i) { return (b >> i) & 1; }
, the >>
operator performs a ______ shift.
In the function int test(unsigned char b, int i) { return (b >> i) & 1; }
, the >>
operator performs a ______ shift.
Match the following operators with their function:
Match the following operators with their function:
In the context of strings, what does 'null-terminated' mean?
In the context of strings, what does 'null-terminated' mean?
The size of a 'word' is consistent across all CPU architectures.
The size of a 'word' is consistent across all CPU architectures.
What is the purpose of prefixing a hexadecimal number with '0x'?
What is the purpose of prefixing a hexadecimal number with '0x'?
The process of accessing data in memory is commonly referred to as ______.
The process of accessing data in memory is commonly referred to as ______.
Match the following terms to their descriptions:
Match the following terms to their descriptions:
Which encoding uses a variable number of bytes to represent characters, and is backward compatible with ASCII for the first 128 characters?
Which encoding uses a variable number of bytes to represent characters, and is backward compatible with ASCII for the first 128 characters?
Bitwise operators are used for control flow decisions in most programming languages.
Bitwise operators are used for control flow decisions in most programming languages.
Explain the role of the null character in string representation within the C programming language.
Explain the role of the null character in string representation within the C programming language.
The ______ operator in C performs a bitwise exclusive OR (XOR) operation.
The ______ operator in C performs a bitwise exclusive OR (XOR) operation.
Match the following hexadecimal values with their decimal equivalents:
Match the following hexadecimal values with their decimal equivalents:
What determines whether a system uses Big Endian or Little Endian byte ordering?
What determines whether a system uses Big Endian or Little Endian byte ordering?
0xAF & 0xF0
will always be equal to 0xAF
0xAF & 0xF0
will always be equal to 0xAF
Explain why hexadecimal representation is preferred over decimal when discussing memory addresses or binary data.
Explain why hexadecimal representation is preferred over decimal when discussing memory addresses or binary data.
If x = 5
and you perform a left bit shift operation x << 2
, the new value of x will be ______.
If x = 5
and you perform a left bit shift operation x << 2
, the new value of x will be ______.
Match the size to unit
Match the size to unit
This question is incredibly challenging and requires abstract thinking. Consider a hypothetical computer architecture where each byte is composed of 7 bits instead of the conventional 8. If a programmer needs to store exactly 100 unique alphanumeric ASCII characters (which normally require 7 bits each to represent) and each character must take up a complete byte, how much memory, in these 7-bit bytes, will be needed to store these 100 characters?
This question is incredibly challenging and requires abstract thinking. Consider a hypothetical computer architecture where each byte is composed of 7 bits instead of the conventional 8. If a programmer needs to store exactly 100 unique alphanumeric ASCII characters (which normally require 7 bits each to represent) and each character must take up a complete byte, how much memory, in these 7-bit bytes, will be needed to store these 100 characters?
Imagine developing for a highly esoteric system where memory operations are extraordinarily expensive, and only bitwise operations are performant. You're tasked to create a function that efficiently checks if an unsigned integer n
is a power of 4 (i.e., 4^0, 4^1, 4^2, ...). You can't use division, multiplication, or loops. The system uses 32 bit unsigned ints and must be implemented by using a one liner.
Given that powers of 4 have a single bit set at positions that are powers of two (e.g., 1, 4, 16, 64) -- meaning that when you subtract 1 from a power of 4, all bits below the set one will be set to 1, and powers of 4, when expressed in binary, have their '1' bit in an even position (0, 2, 4, 6, 8, etc.). To check this you do not want to just return the comparison operator. With n
being a number to check. Which of the following fulfills the condition?
Imagine developing for a highly esoteric system where memory operations are extraordinarily expensive, and only bitwise operations are performant. You're tasked to create a function that efficiently checks if an unsigned integer n
is a power of 4 (i.e., 4^0, 4^1, 4^2, ...). You can't use division, multiplication, or loops. The system uses 32 bit unsigned ints and must be implemented by using a one liner.
Given that powers of 4 have a single bit set at positions that are powers of two (e.g., 1, 4, 16, 64) -- meaning that when you subtract 1 from a power of 4, all bits below the set one will be set to 1, and powers of 4, when expressed in binary, have their '1' bit in an even position (0, 2, 4, 6, 8, etc.). To check this you do not want to just return the comparison operator. With n
being a number to check. Which of the following fulfills the condition?
Flashcards
What is a bit?
What is a bit?
The basic unit of information in modern computing that can store two different values: 0 or 1.
What is a byte?
What is a byte?
A standard package of bits; today, it typically contains 8 bits and is the smallest addressable unit of memory.
What is word?
What is word?
The unit of information accessed by a CPU; its size (number of bits) depends on the CPU architecture.
What is a paragraph?
What is a paragraph?
Signup and view all the flashcards
What is page?
What is page?
Signup and view all the flashcards
What is hexadecimal?
What is hexadecimal?
Signup and view all the flashcards
How programmers take bytes?
How programmers take bytes?
Signup and view all the flashcards
What is addressing?
What is addressing?
Signup and view all the flashcards
What is byte ordering?
What is byte ordering?
Signup and view all the flashcards
What is Big Endian?
What is Big Endian?
Signup and view all the flashcards
What is Little Endian?
What is Little Endian?
Signup and view all the flashcards
How strings stored as?
How strings stored as?
Signup and view all the flashcards
What is ASCII?
What is ASCII?
Signup and view all the flashcards
What is Unicode?
What is Unicode?
Signup and view all the flashcards
What is Machine Code?
What is Machine Code?
Signup and view all the flashcards
What are Bitwise operators?
What are Bitwise operators?
Signup and view all the flashcards
What are Logical operators?
What are Logical operators?
Signup and view all the flashcards
Bit is?
Bit is?
Signup and view all the flashcards
Data Access and addressing?
Data Access and addressing?
Signup and view all the flashcards
Hexadecimal representation?
Hexadecimal representation?
Signup and view all the flashcards
Byte is ordered?
Byte is ordered?
Signup and view all the flashcards
String in memory?
String in memory?
Signup and view all the flashcards
Bit manipulation done by?
Bit manipulation done by?
Signup and view all the flashcards
Study Notes
Information Storage
- Assignment 0 is due on January 26
- Lab 2 is this week
Lecture Contents
- Bits, Bytes, Words, Paragraphs, and Pages will be covered
- Hexadecimal Representation will be covered
- Addressing and Byte Ordering will be covered
- Representing Strings and Code will be covered
- Bitwise and Logical Operations will be covered
Bits
- The bit is the basic unit of information in modern computing
- A bit can store two different values: 0 (no electric current) and 1 (electric current)
- A computer's memory is a collection of elements that store one bit of information each
- Bits are too small to be useful on their own
- Addressing individual bits in memory is complex
- Bits are accessed in packages (bytes, words, paragraphs, or pages)
Data Sizes
- A byte is the "standard" smallest package of bits
- Today, a byte contains 8 bits.
- Bytes were 6-9 bits long
- Bytes are uniquely addressable
- A word is the unit of information access by a CPU
- Words can be 8, 16, 32, 64, or 128 bits, depending on the CPU
- A word is the amount of information transferred between the CPU and main memory in one go
- A paragraph is typically 16 bytes (128 bits)
- A page is typically 4KB (4096 bytes) or 8KB (8192 bytes)
- Page size depends on hardware and the system
- A page is the amount of information transferred between main memory and secondary storage
Memory
- Memory is a physical byte array, where each element has a unique address
- Addresses range from 0 to n-1, where n is the size of the memory
Programmers
- Most programming languages access information at the byte level, at the same level that is addressable in memory
- Since each byte has a unique address, programs can access and manipulate each byte
Hexadecimal Notation
- Bits, bytes, words, and paragraphs are all powers of 2
- Computations often multiplying and dividing by 2
- Multiplying and dividing by 2 in binary is easy (add or remove a 0)
- Writing and reading in binary is difficult
- Octal (base 8) is an altenative
Octal
- Octal is a base-8 number system
- Decimal 8 is Octal 10
- Multiplying a number by 8 adds a 0 to the end
- Every 3-bit number is represented by a single octal digit
- Early bytes were 6 or 9 bits long, so a byte was represented by two or three octal digits, and octal was used in early computer systems
- Today a byte is 8 bits long
- A byte requires 3 octal digits (8/3 = 2.66) to be represented
- Idea: Have the number of bits per digit divides nicely into 8
Hexadecimal
- Idea: Have # of bits per digit divides nicely into 8
- Hexadecimal Number System has 16 digits: 0-9, A-F
- Each digit in hexadecimal can be presented with only 4 bits
- Base 16 multiplies numbers by 16, and then adds a zero at the end
- Avoids conversion mistakes
- Arithmetic rules apply
- Fewer digits
- Multiplying a number by 16 adds a 0 to the end
- Prefix hex representations with 0x
Addressing
- Addressing describes how data is located in memory
- Addressing is relatively standard
- Each byte has a unique address, in increasing order
- Data in memory will uses one or more bytes
- The address of a piece of data is the address of the first byte
Byte Ordering
- Byte ordering is the order of bytes in a piece of data. String byte order depends on the data
- There are two common byte orders for numerical data types, such as Integers (short, int, long), Floats (float, double), Pointers
- Big Endian: bytes are ordered from most significant to least significant
- Little Endian: bytes are ordered from least significant to most significant
Big Endian vs Little Endian
- Byte ordering depends on the CPU
- No order is intrinsically better than the other
Scenarios
- When reading/writing binary data to files
- When receiving/sending binary data over a network
- When exchanging data between different computer architectures
- When debugging and looking at the raw data in memory
Strings
- Strings are stored as a sequence of bytes in memory
- Languages usually use null-terminated string
- A string may consist of 0 or more bytes, none of which is nul (0).
- The string is terminated by a nul (0) character
- A string of n characters takes n+1 bytes to store
- ASCII: American Standard Code for Information Interchange
- Simple, all characters are one byte in size, originally only 7 of 8 bits are used
- Cannot encode non-English characters
- Cannot encode special symbols beyond the standard ones. ` Unicode can encode characters from most known languages UTF-16 uses 2 bytes per character (for most characters) UTF-8 is a variable-length encoding that is the same as ASCII for the first 128 characters. It will assume that all character is ASCII encoding
Key Points
- The fundamental unit of data is the bit, but data is addressed in packages of bytes, words, paragraphs, etc
- Hexadecimal representation aligns with data sizes in the modern computer systems & should be used instead of decimal
- When exchanging binary data between systems, byte ordering is critical because it is hardware-dependent
- Strings are typically stored a nul-terminated sequence of bytes using ASCII or Unicode encoding
- Bit manipulation involves manipulating data values containing the bits
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Lecture covers bits, bytes, words and hexadecimal representation. Addressing and byte ordering along with representing strings and code will be discussed. Topics include the bit as the basic unit of information and data sizes.