Skip to main content
Speclore

Data Types

Data types reference explaining numeric, text, Boolean, and composite values, binary representation, storage, type selection for programming and engineering.

By Merrick S

datatypesData Table

Overview

A data type fixes how many bits a value occupies and how those bits are interpreted. The C/C++ integer types come in signed and unsigned variants at 8, 16 and 32 bits, and each doubling of width squares the number of representable values. Signed integers use two's complement, so half the range lies below zero. Floating-point types follow IEEE 754 and trade exact integer range for a much wider exponent range.

Data Types and Value Ranges

8 rows
Common C/C++ data types with their bit sizes and value ranges.
Unsigned char80 to 255
Signed char8-128 to 127
Unsigned short160 to 65535
Signed short16-32768 to 32767
Unsigned int320 to 4294967295
Signed int32-2147483648 to 2147483647
Float32-3.4028×10^38 to 3.4028×10^38
Double64-1.7977×10^308 to 1.7977×10^308

Source: engineeringtoolbox.com

Binary Representation and Examples

Understanding data types involves how values are encoded in binary. Key concepts include:

  • Byte: One byte is equivalent to 8 bits.
  • Signed vs. unsigned: For signed types, the most significant bit (MSB) indicates the sign: 0 for positive, 1 for negative. Unsigned types only represent non-negative values, using all bits for magnitude.
  • Two's complement: Signed integers typically use two's complement representation, where negative numbers are derived by inverting bits and adding one.

Illustrative examples:

  • Unsigned char (8 bits): The binary 01100100 represents 100 in decimal.
  • Signed char (8 bits): The binary 01100100 is 100, while 10011100 represents -100 using two's complement.
  • Larger types: For short, int, float and double, similar principles apply with extended bit patterns. Float and double follow IEEE 754 standards for floating-point encoding, as seen in their binary representations for values like 100 and -100.

For precise binary conversions, tools like binary-to-decimal converters can be helpful.

References