Data Types & Number Representation
Complete learning module on Data Types, Fixed-Point Representation and Floating-Point Representation for BSc CS, BCA & MCA students.
1. Data Types in Digital Computers
A data type defines the type of data that a variable can store, the amount of memory required, and the operations allowed on it.
Major Categories
- Integer (signed / unsigned)
- Fixed-point numbers
- Floating-point numbers
- Character and Boolean
Data type determines range, precision and arithmetic behavior.
1A. Classification of Data Types (Exam Depth)
1. Primitive / Basic Data Types
- Integer – Whole numbers (signed / unsigned)
- Floating-point – Real numbers with fractions
- Character – ASCII / Unicode representation
- Boolean – True / False (1 bit logically)
2. Derived Data Types
- Arrays
- Structures
- Unions
3. User-Defined Data Types
- enum
- typedef
Explain classification of data types with examples.
→ Determines memory size
→ Controls arithmetic behavior
→ Affects precision and overflow
1B. Role of Data Types in Computer Systems
In a digital computer, data types act as a bridge between hardware representation and high-level programming languages.
Why Data Types Are Fundamentally Important
- Define how data is stored in memory (bit pattern)
- Determine the range of values that can be represented
- Control arithmetic behavior (overflow, underflow, rounding)
- Enable correct interpretation by CPU instructions
Data types specify the format, size, and operations applicable to data in a computer system.
1C. Hardware-Level View of Data Types
At hardware level, a computer does not recognize data types like int, float, or char. It only processes binary patterns.
• 65 (integer)
• ‘A’ (ASCII character)
• part of floating-point mantissa
The interpretation depends on the data type used by the program.
Does hardware understand data types?
Answer: No. Data types are a software-level abstraction.
1D. Signed and Unsigned Data Types
Signed Data Types
- Can represent both positive and negative values
- Use a sign bit (usually MSB)
- Commonly represented using 2’s complement
Unsigned Data Types
- Represent only non-negative values
- No sign bit
- Wider positive range
Unsigned data types cannot represent negative numbers.
1E. Data Type Size and Memory Allocation
Each data type occupies a fixed amount of memory, which affects both performance and storage efficiency.
| Data Type | Typical Size | Purpose |
|---|---|---|
| char | 1 byte | Characters, symbols |
| int | 4 bytes | Integer arithmetic |
| float | 4 bytes | Real numbers (approx.) |
| double | 8 bytes | High precision real numbers |
Selection of appropriate data type optimizes memory usage.
1F. Data Types and Arithmetic Errors
Errors in computation often arise due to improper data type selection.
Common Errors
- Overflow – value exceeds maximum range
- Underflow – value smaller than minimum representable
- Truncation – loss of fractional part
- Rounding error – approximation in floating-point
Incorrect data type choice can lead to logical errors without compilation errors.
1G. Data Types vs Number Representation
Although closely related, data types and number representation are not the same.
| Aspect | Data Type | Number Representation |
|---|---|---|
| Level | Programming / Software | Hardware / Binary |
| Examples | int, float | 2’s complement, IEEE-754 |
| Purpose | Defines usage | Defines storage format |
Data type defines what the data means, representation defines how it is stored.
Data Types – Exam & Viva Questions
- Define data type. Why is it required?
- Explain signed and unsigned data types.
- How does data type affect memory allocation?
- Why floating-point data types are approximate?
- Differentiate data type and number representation.
2. Fixed-Point Representation
In fixed-point representation, the decimal point is fixed at a predefined position.
Characteristics
- Fast arithmetic
- Limited range and precision
- Used in embedded systems
Value = Integer × 2⁻ⁿ
Fixed-Point Playground
2A. Fixed-Point Scaling & Error Analysis
What is Scaling?
Scaling means multiplying or dividing a number by a fixed power of 2 to represent fractions using integers.
Example
Integer value = 90
Actual value = 90 / 2⁴ = 5.625
Quantization Error
Fixed-point cannot represent all decimal fractions exactly. The difference between actual and represented value is called quantization error.
Fixed-point arithmetic introduces quantization error due to limited fractional bits.
2B. Fixed-Point Range Calculator
3. Floating-Point Representation
Floating-point representation stores numbers in scientific notation form.
IEEE-754 (32-bit) Components
- 1 bit → Sign
- 8 bits → Exponent (biased)
- 23 bits → Mantissa
Floating-Point Playground
3A. Floating-Point Normalization
In IEEE floating-point, numbers are stored in normalized form so that the mantissa always starts with 1.
Why Normalization?
- Maximizes precision
- Unique representation
- Efficient storage
3B. Floating-Point Errors
Why Errors Occur
- Binary cannot represent all decimal fractions
- Limited mantissa bits
- Rounding after each operation
Types of Errors
- Rounding error
- Overflow
- Underflow
Floating-point arithmetic is approximate, not exact.
3C. Floating-Point Precision Demonstration
Fixed-Point vs Floating-Point
| Feature | Fixed-Point | Floating-Point |
|---|---|---|
| Speed | Faster | Slower |
| Precision | Limited | High |
| Range | Small | Very Large |
| Hardware | Simple | Complex (FPU) |
| Use Case | Embedded systems | Scientific computing |
Exam & Viva Questions
- Define fixed-point representation. Explain with example.
- What is normalization in floating-point?
- Why floating-point arithmetic is inaccurate?
- Compare fixed-point and floating-point.
- Explain IEEE-754 format.
Exam Memory Tricks
- Fixed-point → fast but limited
- Floating-point → wide range, precision errors
- Bias = 2ⁿ⁻¹ − 1
- Decimal fractions may not be exact in binary
