Lecture 5 Bits, Bytes, Words, Paragraphs and Pages
40 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the basic unit of information in modern computing?

  • Bit (correct)
  • Word
  • Paragraph
  • Byte

Bits are commonly accessed individually in memory.

False (B)

What is a byte?

the standard smallest package of bits

A _____ is the unit of information accessed by a CPU.

<p>word</p> Signup and view all the answers

Match the following data sizes with their typical sizes:

<p>Byte = 8 bits Word = 8, 16, 32, 64, or 128 bits Paragraph = 16 bytes (128 bits) Page = 4KB (4096 bytes) or 8KB (8192 bytes)</p> Signup and view all the answers

What is the primary advantage of hexadecimal notation?

<p>It aligns well with powers of 2 and byte sizes. (D)</p> Signup and view all the answers

Octal (base 8) is widely used in modern computing due to its efficient representation of bytes.

<p>False (B)</p> Signup and view all the answers

How many bits does each digit in hexadecimal represent?

<p>4</p> Signup and view all the answers

To indicate that a number is in hexadecimal format, it is often prefixed with _____.

<p>0x</p> Signup and view all the answers

Match the following base number systems with their representation:

<p>Binary = Base 2 Octal = Base 8 Decimal = Base 10 Hexadecimal = Base 16</p> Signup and view all the answers

What does addressing refer to in the context of memory?

<p>How data is located in memory (D)</p> Signup and view all the answers

In a big-endian system, bytes are ordered from least significant to most significant.

<p>False (B)</p> Signup and view all the answers

Define byte ordering.

<p>the order of bytes in a piece of data</p> Signup and view all the answers

In a _____ endian system, bytes are ordered from least significant to most significant.

<p>little</p> Signup and view all the answers

Indicate whether the following are examples of Little Endian or Big Endian:

<p>Most significant byte first = Big Endian Least significant byte first = Little Endian</p> Signup and view all the answers

What is a common characteristic of strings in memory?

<p>They are stored as nul-terminated sequences of bytes. (B)</p> Signup and view all the answers

Unicode encoding always uses one byte per character.

<p>False (B)</p> Signup and view all the answers

How many bytes does the string 'hello' take up in memory if it is nul-terminated and uses ASCII encoding?

<p>6</p> Signup and view all the answers

The encoding standard commonly used in C which represents each character as a single byte is known as _____.

<p>ASCII</p> Signup and view all the answers

Match the following string encoding standards with their properties:

<p>ASCII = 1 byte per character UTF-16 = 2 bytes per character UTF-8 = variable length encoding</p> Signup and view all the answers

What is the fundamental unit of data that can be manipulated using bitwise operations?

<p>Bit (D)</p> Signup and view all the answers

In C, a byte is denoted by the int type.

<p>False (B)</p> Signup and view all the answers

If x = 0xD5 (11010101 in binary) and y = 0x5D (01011101 in binary), what is the result of x & y in binary?

<p>01010101</p> Signup and view all the answers

If x = 0xD5 (11010101 in binary) and y = 0x5D (01011101 in binary), the result of x | y is _____ in binary.

<p>11011101</p> Signup and view all the answers

Match the given Assembly instruction with its explaination

<p>push %rbp = Push the base pointer onto the stack mov %rsp, %rbp = Move the stack pointer to the base pointer lea 0x0(%rip), %rdi = Load the effective address relative to the instruction pointer into %rdi retq = Return from a subroutine</p> Signup and view all the answers

What is the purpose of the following C code? return (b >> i) & 1;

<p>Return the value of the ith bit in b (A)</p> Signup and view all the answers

Bytes are uniquely addressable in memory!

<p>True (A)</p> Signup and view all the answers

What is the purpose of bitwise operators?

<p>perform operations at the bit level</p> Signup and view all the answers

A string of _____ characters takes n+1 bytes to store

<p>n</p> Signup and view all the answers

Match number system with its base

<p>Binary = Base 2 Octal = Base 8 Decimal = Base 10 Hexadecimal = Base 16</p> Signup and view all the answers

Which task is NOT typically a reason to care about byte ordering?

<p>Writing comments in source code (D)</p> Signup and view all the answers

A single bit does store enough useful information on its own.

<p>False (B)</p> Signup and view all the answers

What is null terminated string?

<p>A string that ends with a null character (0)</p> Signup and view all the answers

A _____ is 16-bytes (128-bits) in size (typically)

<p>paragraph</p> Signup and view all the answers

Match the bitwise operator with its function:

<p>AND = If both bits are 1, the result is 1. Otherwise, the result is 0. OR = If at least one of the bits is 1, the result is 1. Otherwise, the result is 0. NOT = Inverts the bits XOR = If the bits are different, the result is 1. If the bits are the same, the result is 0.</p> Signup and view all the answers

If w = 0xff, what is !w?

<p>0 (B)</p> Signup and view all the answers

Multiplying a number by 8 in Octal adds a digit zero to its value at the end.

<p>True (A)</p> Signup and view all the answers

Explain what is hexadecimal number system in short.

<p>A base 16 number system</p> Signup and view all the answers

The memory of computer is a large collection of elements, each of which stores one _____ of infomation

<p>bit</p> Signup and view all the answers

What is the result of 1048576 (base 10) = ? (base 4)?

<p>10000000000 (D)</p> Signup and view all the answers

Flashcards

What is a bit?

The basic unit of information in modern computing, storing two different values (0 or 1).

What is a byte?

The 'standard' smallest package of bits, typically containing 8 bits.

What is a word?

Unit of information accessed by a CPU, with size depending on the CPU.

What is a paragraph?

A package of 16 bytes (128 bits).

Signup and view all the flashcards

What is a page?

Hardware and system-dependent, amount of data transferred between main memory and secondary storage.

Signup and view all the flashcards

What is hexadecimal?

A base-16 numbering system using digits 0-9 and letters A-F.

Signup and view all the flashcards

What is addressing?

How data is located in memory involving unique and increasing memory address.

Signup and view all the flashcards

What is byte ordering?

Refers to the order of bytes in some piece of data.

Signup and view all the flashcards

What is Big Endian?

Bytes ordered from most significant to least significant.

Signup and view all the flashcards

What is Little Endian?

Bytes are ordered from least significant to most significant.

Signup and view all the flashcards

What are strings?

Stored as sequence of bytes in memory, often nul-terminated.

Signup and view all the flashcards

What is Machine code?

Each program instruction is a sequence of one or more bytes.

Signup and view all the flashcards

What are Bitwise Operators?

Operators that work on bits of data values for low-level manipulation.

Signup and view all the flashcards

What are Logical Operators?

Operators that work on entire values and are used for control flow.

Signup and view all the flashcards

Study Notes

Bits and Bytes

  • The bit is the fundamental unit of information; it can store two values: 0 (no electric current) and 1 (electric current).
  • Computer memory is a collection of elements, each storing one bit.
  • Bits are typically accessed in packages of bytes, words, paragraphs, or pages because single bits are too small to be useful to access by themselves.
  • A byte is considered the smallest standard package of bits.
  • Today, a byte contains 8 bits, but in the past, bytes ranged from 6-9 bits.
  • Bytes are uniquely addressable in memory.
  • A word is the unit of information accessed by a CPU, typically 8, 16, 32, 64, or 128 bits.
  • A word is the amount of information that can be transferred between the CPU and main memory in one go.
  • A paragraph is usually 16 bytes (128 bits).
  • A page is typically 4KB (4096 bytes) or 8KB (8192 bytes) depending on the hardware and system.
  • A page is the amount of information transferred between main memory and secondary storage.
  • Programming languages can access information at the byte level, which contains a unique address in physical memory.

Hexadecimal Notation

  • Bits, bytes, words, and paragraphs are all powers of 2.
  • Computations often involve multiplying and dividing by 2.
  • Multiplying or dividing by 2 easier in binary (adding/removing a 0).
  • Octal (base 8) requires 3 digits to represent a byte, but the most significant octal digit is not fully used.
  • Hexadecimal (base 16) provides a solution since the number of bits per digit divides nicely into 8 (4 bits per digit).
  • Doing everything in hex avoids conversion mistakes and uses fewer digits.
  • To convert decimal to hex, repeatedly divide the decimal value by 16. The remainders form digits in the hex representation. (e.g., 23512 (decimal) == 5BD8 (hex)).
  • To convert hex to decimal, multiply each hex digit by increasing powers of 16 and add the results (e.g. 5BD8 (hex) == 23512 (decimal)).
  • Use the prefix 0x to indicate a value is in hex.

Addressing and Byte Ordering

  • Addressing shows how data is located in memory.
  • Each byte has a unique address in increasing order, in a relatively standard manner.
  • A piece of data in memory consists of one or more bytes, and its address is the address of the first byte.
  • Byte ordering refers to the order of bytes in a piece of data.
  • The order of bytes for strings depends on the data itself.
  • There are two byte orders for numerical data types, such as integers and floating-point numbers.
  • Big Endian orders bytes from most significant to least significant.
  • Little Endian orders bytes from least significant to most significant.
  • Byte ordering depends on the hardware, or CPU.
  • Applications for reading and writing binary data to files and receiving and transferring binary data over networks may depend on byte order. Exchanging data between computer architectures and debugging tasks can rely on byte ordering.

Strings and Encoding

  • Strings are stored as sequences of bytes in memory and are often null-terminated (end with a 0).
  • A string of n characters takes n+1 bytes to store because of the null terminator.
  • Strings are commonly encoded in ASCII (1 byte per character) or Unicode (often 2 bytes per character).
  • The American Standard Code for Information Interchange (ASCII) typically uses a single byte for all characters, and cannot encode non-English characters or special characters.
  • Unicode is able to encode characters from many languages (UTF-16 uses two bytes per character, UTF-8 for English characters).

Machine Code

  • Program instructions are stored as sequences of one or more bytes.
  • The CPU moves a pointer in memory as it executes program instructions.

Bitwise and Logical Operations

  • Individual bits cannot be addressed directly in programs.
  • Bytes or words can be used to find bits.
  • In C, a byte is the "char" type, and a word is the "int" type.
  • test(unsigned char b, int i) right shifts a char, (byte), b, by i and performs a bitwise AND with 1 to get the value of bit i.
  • Bitwise operators work on the bits of values, and logical operators test entire values.

Bitwise Operator Summary:

  • ~ Negates all bits (~x).
  • & Bitwise AND: x & y.
  • | Bitwise OR: x | y.
  • ^ Bitwise XOR: x ^ y.
  • >> Right shift: x >> 3 (shifts bits 3 places to the right).
  • << Left shift: x << 3 (shifts bits 3 places to the left).

Logical Operator Summary:

  • ! Negates a value: !x (0 if x is non-zero, 1 if x is zero).
  • && Logical AND: x && y (1 if both x and y are non-zero, else 0).
  • || Logical OR: Example: x || y (1 if either x or y is non-zero, else 0).

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

Explanation of bits, bytes, words, paragraphs and pages. The bit is the fundamental unit of information; it can store two values: 0 and 1. Computer memory is a collection of elements, each storing one bit. A byte is the smallest standard package of bits.

More Like This

Use Quizgecko on...
Browser
Browser