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
Integer (8-bit signed): −128 to +127
Exam Tip:
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
Exam Question:
Explain classification of data types with examples.
Why data types matter?
→ 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
Exam Statement:
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.

01000001 → interpreted as
• 65 (integer)
• ‘A’ (ASCII character)
• part of floating-point mantissa

The interpretation depends on the data type used by the program.

Viva Question:
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
8-bit signed integer range: −128 to +127

Unsigned Data Types

  • Represent only non-negative values
  • No sign bit
  • Wider positive range
8-bit unsigned integer range: 0 to 255
Exam Trap:
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 TypeTypical SizePurpose
char1 byteCharacters, symbols
int4 bytesInteger arithmetic
float4 bytesReal numbers (approx.)
double8 bytesHigh precision real numbers
Exam Line:
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
Using int instead of float → loss of fractional data
Exam Tip:
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.

AspectData TypeNumber Representation
LevelProgramming / SoftwareHardware / Binary
Examplesint, float2’s complement, IEEE-754
PurposeDefines usageDefines storage format
Exam Line:
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
Q4.4 format → 4 integer bits, 4 fractional bits
Value Formula:
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.

Q-format Qm.n → m integer bits, n fractional bits

Example

Binary: 01011010 (Q4.4)
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.

Exam Line:
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.

Number = Sign × Mantissa × 2Exponent

IEEE-754 (32-bit) Components

  • 1 bit → Sign
  • 8 bits → Exponent (biased)
  • 23 bits → Mantissa
Bias (Single Precision): 127

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.

13.25₁₀ = 1101.01₂ = 1.10101 × 2³

Why Normalization?

  • Maximizes precision
  • Unique representation
  • Efficient storage
Hidden bit (leading 1) is not stored in IEEE-754.

3B. Floating-Point Errors

Why Errors Occur

  • Binary cannot represent all decimal fractions
  • Limited mantissa bits
  • Rounding after each operation
0.1₁₀ ≠ exact binary representation

Types of Errors

  • Rounding error
  • Overflow
  • Underflow
Exam Line:
Floating-point arithmetic is approximate, not exact.

3C. Floating-Point Precision Demonstration

Fixed-Point vs Floating-Point

FeatureFixed-PointFloating-Point
SpeedFasterSlower
PrecisionLimitedHigh
RangeSmallVery Large
HardwareSimpleComplex (FPU)
Use CaseEmbedded systemsScientific 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
Designed for Digital Computer Organization & Computer Architecture