Skip to content

Integer

alt text

āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ āĻĄā§‡āϟāĻž āϟāĻžāχāĻĒ⧇āϰ āĻŽā§‡āĻŽā§‹āϰāĻŋ āϏāĻžāχāϜ (Memory Size of Integer Data Type)

  • āϏāĻŋ āĻ˛ā§āϝāĻžāĻ™ā§āĻ—ā§ā§Ÿā§‡āĻœā§‡āϰ āĻāĻ•āϟāĻŋ āĻŽā§ŒāϞāĻŋāĻ• āĻŦāĻž āĻĢāĻžāĻ¨ā§āĻĄāĻžāĻŽā§‡āĻ¨ā§āϟāĻžāϞ āĻĄā§‡āϟāĻž āϟāĻžāχāĻĒ (Fundamental Data Type) āĻšāϞ⧋ āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ (Integer)āĨ¤
  • āĻŽā§‡āĻŽāϰāĻŋāϤ⧇ āĻāϟāĻŋ ⧍ āĻŦāĻžāχāϟ (2 bytes) āĻ…āĻĨāĻŦāĻž ā§Ē āĻŦāĻžāχāϟ (4 bytes) āϜāĻžā§ŸāĻ—āĻž āĻĻāĻ–āϞ āĻ•āϰ⧇, āϝāĻž āĻŽā§‚āϞāϤ āĻŦā§āϝāĻŦāĻšā§ƒāϤ āĻŽā§‡āĻļāĻŋāύ⧇āϰ āφāĻ°ā§āĻ•āĻŋāĻŸā§‡āĻ•āϚāĻžāϰ⧇āϰ āĻ“āĻĒāϰ āĻĄāĻŋāĻĒ⧇āĻ¨ā§āĻĄ āĻ•āϰ⧇āĨ¤
  • āφāĻŽāϰāĻž āϜāĻžāύāĻŋ ā§§ āĻŦāĻžāχāϟ āϏāĻŽāĻžāύ ā§Ž āĻŦāĻŋāϟ, āϏ⧇āχ āĻšāĻŋāϏāĻžāĻŦ⧇ ⧍ āĻŦāĻžāχāϟ āĻŽāĻžāύ⧇ ā§§ā§Ŧ āĻŦāĻŋāϟ āĻāĻŦāĻ‚ ā§Ē āĻŦāĻžāχāϟ āĻŽāĻžāύ⧇ ā§Šā§¨ āĻŦāĻŋāϟāĨ¤ āĻŽā§‡āĻŽāϰāĻŋāϰ āϏāĻžāχāϜ āϝāϤ āĻŦ⧇āĻļāĻŋ āĻšāĻŦ⧇, āĻ­ā§āϝāĻžāϰāĻŋā§Ÿā§‡āĻŦāϞ⧇āϰ āĻĄā§‡āϟāĻž āĻŦāĻž āĻ•āĻ¨ā§āĻŸā§‡āĻ¨ā§āϟ āĻšā§‹āĻ˛ā§āĻĄ āĻ•āϰāĻžāϰ āĻ•ā§āώāĻŽāϤāĻžāĻ“ āϤāϤ āĻŦāĻžā§œāĻŦ⧇āĨ¤

sizeof āĻ…āĻĒāĻžāϰ⧇āϟāϰ⧇āϰ āĻŦā§āϝāĻŦāĻšāĻžāϰ (Use of sizeof Operator)

  • āϕ⧋āĻĄā§‡āϰ āĻŽāĻžāĻ§ā§āϝāĻŽā§‡ āĻĒā§āϰ⧋āĻ—ā§āϰāĻžāĻŽāĻžāϟāĻŋāĻ•ā§āϝāĻžāϞāĻŋ āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ⧇āϰ āĻāĻ•āϚ⧁⧟āĻžāϞ āϏāĻžāχāϜ āϜāĻžāύāϤ⧇ āϏāĻŋ āĻ˛ā§āϝāĻžāĻ™ā§āĻ—ā§ā§Ÿā§‡āĻœā§‡ sizeof āĻ…āĻĒāĻžāϰ⧇āϟāϰ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻž āĻšā§ŸāĨ¤
  • āĻāĻ•āϟāĻŋ āϗ⧁āϰ⧁āĻ¤ā§āĻŦāĻĒā§‚āĻ°ā§āĻŖ āĻŸā§‡āĻ•āύāĻŋāĻ•ā§āϝāĻžāϞ āĻŦāĻŋāώ⧟ āĻšāϞ⧋, sizeof āϕ⧋āύ⧋ āĻĢāĻžāĻ‚āĻļāύ āύ⧟, āĻāϟāĻŋ āĻāĻ•āϟāĻŋ āχāωāύāĻžāϰāĻŋ āĻ…āĻĒāĻžāϰ⧇āϟāϰ (Unary Operator)āĨ¤
  • āĻŽā§‡āĻļāĻŋāύ⧇ āϝāĻĻāĻŋ āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ ā§Ē āĻŦāĻžāχāϟ āϜāĻžā§ŸāĻ—āĻž āĻ¨ā§‡ā§Ÿ, āϤāĻŦ⧇ printf āĻĢāĻžāĻ‚āĻļāύ⧇āϰ āĻŽāĻžāĻ§ā§āϝāĻŽā§‡ āĻāχ āĻ…āĻĒāĻžāϰ⧇āϟāϰāϟāĻŋ āφāωāϟāĻĒ⧁āϟ āĻšāĻŋāϏ⧇āĻŦ⧇ ā§Ē āĻĒā§āϰāĻĻāĻ°ā§āĻļāύ āĻ•āϰāĻŦ⧇āĨ¤

āĻĄā§‡āϟāĻž āϏ⧇āĻŸā§‡āϰ āϰ⧇āĻžā§āϜ (Definition of Range)

  • āϰ⧇āĻžā§āϜ (Range) āĻŦāϞāϤ⧇ āĻŽā§‚āϞāϤ āϕ⧋āύ⧋ āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ āĻĄā§‡āϟāĻž āϏ⧇āĻŸā§‡āϰ āϏāĻ°ā§āĻŦā§‹āĻšā§āϚ āĻāĻŦāĻ‚ āϏāĻ°ā§āĻŦāύāĻŋāĻŽā§āύ āϏ⧀āĻŽāĻžāϕ⧇ (Upper and lower limit) āĻŦā§‹āĻāĻžā§ŸāĨ¤
  • āωāĻĻāĻžāĻšāϰāĻŖāĻ¸ā§āĻŦāϰ⧂āĻĒ, āĻāĻ•āϟāĻŋ āĻĄā§‡āϟāĻž āϏ⧇āϟ āϝāĻĻāĻŋ {0, 1, 2, 3, 4} āĻšā§Ÿ, āϤāĻŦ⧇ āĻāϰ āϏāĻ°ā§āĻŦāύāĻŋāĻŽā§āύ āĻŽāĻžāύ ā§Ļ āĻāĻŦāĻ‚ āϏāĻ°ā§āĻŦā§‹āĻšā§āϚ āĻŽāĻžāύ ā§Ē; āĻ…āĻ°ā§āĻĨāĻžā§Ž āĻāϰ āϰ⧇āĻžā§āϜ āĻšāϞ⧋ ā§Ļ āĻĨ⧇āϕ⧇ ā§Ē āĻĒāĻ°ā§āϝāĻ¨ā§āϤāĨ¤ āĻāχ āϏ⧇āĻŸā§‡āϰ āϭ⧇āϤāϰ ā§Ļ āĻāϰ āĻšā§‡ā§Ÿā§‡ āϛ⧋āϟ āĻŦāĻž ā§Ē āĻāϰ āĻšā§‡ā§Ÿā§‡ āĻŦ⧜ āϕ⧋āύ⧋ āĻŽāĻžāύ āĻĨāĻžāĻ•āϤ⧇ āĻĒāĻžāϰāĻŦ⧇ āύāĻžāĨ¤

āĻĄā§‡āϏāĻŋāĻŽāĻžāϞ āύāĻžāĻŽā§āĻŦāĻžāϰ āϏāĻŋāĻ¸ā§āĻŸā§‡āĻŽ (Decimal Number System)

  • āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ⧇āϰ āϰ⧇āĻžā§āϜ āĻ•ā§āϝāĻžāϞāϕ⧁āϞ⧇āĻļāύ āĻ­āĻžāϞ⧋āĻ­āĻžāĻŦ⧇ āĻŦā§‹āĻāĻžāϰ āĻĢāĻžāĻ¸ā§āϟ āĻĒā§āϰāĻŋ-āϰāĻŋāϕ⧁āχāϜāĻŋāϟ (Prerequisite) āĻšāϞ⧋ āĻĄā§‡āϏāĻŋāĻŽāĻžāϞ āύāĻžāĻŽā§āĻŦāĻžāϰ āϏāĻŋāĻ¸ā§āĻŸā§‡āĻŽ āĻŦāĻž āĻĻāĻļāĻŽāĻŋāϕ⧇ āϏāĻ‚āĻ–ā§āϝāĻžāϰ āĻ—āĻ āύ āϜāĻžāύāĻžāĨ¤
  • āĻāϟāĻŋ āĻŽāĻžāύ⧁āώ⧇āϰ āĻŦā§‹āϧāĻ—āĻŽā§āϝ āĻāĻ•āϟāĻŋ āĻĒāĻĻā§āϧāϤāĻŋ āĻāĻŦāĻ‚ āĻāϕ⧇ āĻŦ⧇āϏ ā§§ā§Ļ (Base 10) āύāĻžāĻŽā§āĻŦāĻžāϰ āϏāĻŋāĻ¸ā§āĻŸā§‡āĻŽ āĻŦāϞāĻž āĻšā§Ÿ, āϝāĻžāϰ āĻŽāĻžāύ⧇ āĻāĻ–āĻžāύ⧇ ā§Ļ āĻĨ⧇āϕ⧇ ⧝ āĻĒāĻ°ā§āϝāĻ¨ā§āϤ āĻŽā§‹āϟ ā§§ā§ĻāϟāĻŋ āĻĄāĻŋāϜāĻŋāϟ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻž āϝāĻžā§ŸāĨ¤
  • āϝ⧇āĻŽāύ ā§Ģā§Ŧā§Ž (568) āϏāĻ‚āĻ–ā§āϝāĻžāϟāĻŋāϕ⧇ āφāĻŽāϰāĻž āϏāϰāĻžāϏāϰāĻŋ 'āĻĒāĻžāρāϚāĻļāϤ āφāϟāώāĻŸā§āϟāĻŋ' āĻŦāϞāĻŋ āĻ•āĻžāϰāĻŖ āĻāϰ āϭ⧇āϤāϰ⧇āϰ āĻĒā§āϰāϤāĻŋāϟāĻŋ āĻĄāĻŋāϜāĻŋāϟāϕ⧇ āϤāĻžāϰ āĻĄāĻžāύāĻĻāĻŋāϕ⧇āϰ āĻļ⧇āώ āĻĒā§āϰāĻžāĻ¨ā§āϤ āĻĨ⧇āϕ⧇ āύāĻŋāϜāĻ¸ā§āĻŦ āĻĒā§āϞ⧇āϏ āĻ­ā§āϝāĻžāϞ⧁ āĻŦāĻž āĻ¸ā§āĻĨāĻžāĻ¨ā§€ā§Ÿ āĻŽāĻžāύ (Place values) āĻĻāĻŋā§Ÿā§‡ āϗ⧁āĻŖ āĻ•āϰāĻž āĻšā§Ÿ (\(8 \times 10^0 = 8\), \(6 \times 10^1 = 60\), \(5 \times 10^2 = 500\)) āĻāĻŦāĻ‚ āϏāĻŦāĻļ⧇āώ⧇ āϗ⧁āĻŖāĻĢāϞāϗ⧁āϞ⧋ āϝ⧋āĻ— āĻ•āϰ⧇ āĻšā§‚ā§œāĻžāĻ¨ā§āϤ āĻŽāĻžāύ ā§Ģā§Ŧā§Ž āĻĒāĻžāĻ“ā§ŸāĻž āϝāĻžā§ŸāĨ¤

āĻŦāĻžāχāύāĻžāϰāĻŋ āύāĻžāĻŽā§āĻŦāĻžāϰ āϏāĻŋāĻ¸ā§āĻŸā§‡āĻŽ (Binary Number System)

  • āĻ•āĻŽā§āĻĒāĻŋāωāϟāĻžāϰ āĻĄā§‡āϏāĻŋāĻŽāĻžāϞ āĻŦā§‹āĻā§‡ āύāĻž, āĻāϰ āϭ⧇āϤāϰ⧇āϰ āĻŽā§‚āϞ āϖ⧇āϞ āϚāϞ⧇ āĻŦāĻžāχāύāĻžāϰāĻŋ āύāĻžāĻŽā§āĻŦāĻžāϰ āϏāĻŋāĻ¸ā§āĻŸā§‡āĻŽ (Binary Number System) āĻŦāĻž āĻŦ⧇āϏ ⧍ (Base 2) āĻĒāĻĻā§āϧāϤāĻŋ āĻĻāĻŋā§Ÿā§‡, āϝ⧇āĻ–āĻžāύ⧇ āϕ⧇āĻŦāϞ ā§Ļ āĻāĻŦāĻ‚ ā§§ āĻāχ āĻĻ⧁āϟāĻŋ āĻĄāĻŋāϜāĻŋāϟ āĻĨāĻžāϕ⧇āĨ¤
  • ā§Ē-āĻŦāĻŋāĻŸā§‡āϰ āĻāĻ•āϟāĻŋ āĻŦāĻžāχāύāĻžāϰāĻŋ āĻĄā§‡āϟāĻž 1100 āĻāϰ āĻĄā§‡āϏāĻŋāĻŽāĻžāϞ āĻŽāĻžāύ āĻŦ⧇āϰ āĻ•āϰāϤ⧇ āĻšāϞ⧇ āĻĄāĻžāύāĻĻāĻŋāϕ⧇āϰ āĻļ⧇āώ āĻĒā§āϰāĻžāĻ¨ā§āϤ āĻĨ⧇āϕ⧇ ⧍ āĻāϰ āĻĒāĻžāĻ“ā§ŸāĻžāϰ⧇āϰ āĻĒā§āϞ⧇āϏ āĻ­ā§āϝāĻžāϞ⧁āϗ⧁āϞ⧋ (\(2^0, 2^1, 2^2, 2^3\)) āĻĻāĻŋā§Ÿā§‡ āĻĄāĻŋāϜāĻŋāϟāϗ⧁āϞ⧋āϕ⧇ āϗ⧁āĻŖ āĻ•āϰāϤ⧇ āĻšāĻŦ⧇āĨ¤ āĻšāĻŋāϏāĻžāĻŦāϟāĻŋ āĻšāϞ⧋: \((0 \times 2^0) + (0 \times 2^1) + (1 \times 2^2) + (1 \times 2^3) = 0 + 0 + 4 + 8 = 12\)āĨ¤

ā§Ē-āĻŦāĻŋāϟ āĻĄā§‡āϟāĻžāϰ āϰ⧇āĻžā§āϜ āύāĻŋāĻ°ā§āϪ⧟ (Calculating Range of 4-bit Data)

  • ā§Ē-āĻŦāĻŋāϟ āĻĄā§‡āϟāĻžāϰ āĻ•ā§āώ⧇āĻ¤ā§āϰ⧇ āϏāĻ°ā§āĻŦāύāĻŋāĻŽā§āύ āĻŽāĻžāύ āĻšāϤ⧇ āĻĒāĻžāϰ⧇ ā§Ļ (āϝāĻ–āύ āϏāĻŦ āĻŦāĻŋāϟ ā§Ļ) āĻāĻŦāĻ‚ āϏāĻ°ā§āĻŦā§‹āĻšā§āϚ āĻŽāĻžāύ āĻšāϤ⧇ āĻĒāĻžāϰ⧇ ā§§ā§Ģ (āϝāĻ–āύ āϏāĻŦ āĻŦāĻŋāϟ ā§§)āĨ¤
  • āϝ⧇āϕ⧋āύ⧋ āĻŦ⧜ āĻŦāĻž ā§Šā§¨-āĻŦāĻŋāϟ āĻĄā§‡āϟāĻžāϰ āϏāĻ°ā§āĻŦā§‹āĻšā§āϚ āφāύāϏāĻžāχāĻ¨ā§āĻĄ āĻŽāĻžāύ āĻŦ⧇āϰ āĻ•āϰāĻžāϰ āϜāĻ¨ā§āϝ āĻāĻ•āϟāĻŋ āĻœā§‹āϏ āĻ“ āĻšā§āϝāĻžāĻ¨ā§āĻĄāĻŋ (Handy) āĻĢāĻ°ā§āĻŽā§āϞāĻž āĻšāϞ⧋ \(2^n - 1\)āĨ¤ āĻāĻ–āĻžāύ⧇ āĻŦāĻŋāϟ āϏāĻ‚āĻ–ā§āϝāĻž \(n = 4\) āĻŦāϏāĻžāϞ⧇ āφāĻŽāϰāĻž āĻĒāĻžāχ \(2^4 - 1 = 16 - 1 = 15\), āĻ…āĻ°ā§āĻĨāĻžā§Ž ā§Ē-āĻŦāĻŋāϟ āĻĄā§‡āϟāĻžāϰ āϰ⧇āĻžā§āϜ āĻšāϞ⧋ ā§Ļ āĻĨ⧇āϕ⧇ ā§§ā§ĢāĨ¤

āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ⧇āϰ āϰ⧇āĻžā§āϜ āĻ•ā§āϝāĻžāϞāϕ⧁āϞ⧇āĻļāύ (Integer Range Calculation)

  • ⧍-āĻŦāĻžāχāϟ āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ (16 bits): āϝāĻĻāĻŋ āĻŽā§‡āĻļāĻŋāύ ⧍-āĻŦāĻžāχāϟ āϏāĻžāĻĒā§‹āĻ°ā§āϟ āĻ•āϰ⧇, āϤāĻŦ⧇ āĻāϰ āφāύāϏāĻžāχāĻ¨ā§āĻĄ āϰ⧇āĻžā§āϜ (Unsigned range) āĻšāĻŦ⧇ ā§Ļ āĻĨ⧇āϕ⧇ ā§Ŧā§Ģ,ā§Ģā§Šā§Ģ āĻĒāĻ°ā§āϝāĻ¨ā§āϤ (āĻĢāĻ°ā§āĻŽā§āϞāĻž: \(2^{16} - 1 = 65535\))āĨ¤
  • āϏāĻžāχāύāĻĄ āϰāĻŋāĻĒā§āϰ⧇āĻœā§‡āĻ¨ā§āĻŸā§‡āĻļāύ (Signed Representation): āĻŦāĻžāĻ¸ā§āϤāĻŦ āϕ⧋āĻĄāĻŋāĻ‚ā§Ÿā§‡ āύ⧇āϗ⧇āϟāĻŋāĻ­ āĻŦāĻž āĻ‹āĻŖāĻžāĻ¤ā§āĻŽāĻ• āĻŽāĻžāύāĻ“ āϰāĻŋāĻĒā§āϰ⧇āĻœā§‡āĻ¨ā§āϟ āĻ•āϰāϤ⧇ āĻšā§ŸāĨ¤ āύ⧇āϗ⧇āϟāĻŋāĻ­ āϏāĻ‚āĻ–ā§āϝāĻž āĻĒā§āϰāĻ•āĻžāĻļ⧇āϰ ā§ŠāϟāĻŋ āĻĒāĻĻā§āϧāϤāĻŋ āĻšāϞ⧋: āϏāĻžāχāύāĻĄ āĻŽā§āϝāĻžāĻ—āύāĻŋāϚāĻŋāωāĻĄ (Signed magnitude), ā§§'āϏ āĻ•āĻŽāĻĒā§āϞāĻŋāĻŽā§‡āĻ¨ā§āϟ (1's complement), āĻāĻŦāĻ‚ ⧍'āϏ āĻ•āĻŽāĻĒā§āϞāĻŋāĻŽā§‡āĻ¨ā§āϟ (2's complement)āĨ¤
  • ⧍'āϏ āĻ•āĻŽāĻĒā§āϞāĻŋāĻŽā§‡āĻ¨ā§āϟ āϰ⧇āĻžā§āϜ: āφāϧ⧁āύāĻŋāĻ• āĻ•āĻŽā§āĻĒāĻŋāωāϟāĻžāϰ āϏāĻžāϧāĻžāϰāĻŖāϤ ⧍'āϏ āĻ•āĻŽāĻĒā§āϞāĻŋāĻŽā§‡āĻ¨ā§āϟ āĻŽā§‡āĻĨāĻĄ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧇, āϝāĻžāϰ āϰ⧇āĻžā§āϜ āύāĻŋāĻ°ā§āϧāĻžāϰāϪ⧇āϰ āĻĢāĻ°ā§āĻŽā§āϞāĻž āĻšāϞ⧋ \(-2^{n-1}\) āĻĨ⧇āϕ⧇ \(+2^{n-1} - 1\) āĻĒāĻ°ā§āϝāĻ¨ā§āϤāĨ¤ ⧍-āĻŦāĻžāχāϟ āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ⧇āϰ (\(n=16\)) āĻ•ā§āώ⧇āĻ¤ā§āϰ⧇ āĻšāĻŋāϏāĻžāĻŦ āĻ•āϰāϞ⧇ āϏāĻžāχāύāĻĄ āϰ⧇āĻžā§āϜ āĻĻāĻžāρ⧜āĻžā§Ÿ \(-32,768\) āĻĨ⧇āϕ⧇ \(+32,767\) āĻĒāĻ°ā§āϝāĻ¨ā§āϤāĨ¤
  • ā§Ē-āĻŦāĻžāχāϟ āχāĻ¨ā§āϟāĻŋāϜāĻžāϰ (32 bits): āϝāĻĻāĻŋ āĻŽā§‡āĻļāĻŋāύ ā§Ē-āĻŦāĻžāχāϟ āϏāĻžāĻĒā§‹āĻ°ā§āϟ āĻ•āϰ⧇, āϤāĻŦ⧇ āĻāϰ āφāύāϏāĻžāχāĻ¨ā§āĻĄ āϰ⧇āĻžā§āϜ āĻšāĻŦ⧇ ā§Ļ āĻĨ⧇āϕ⧇ ā§Ē,⧍⧝ā§Ē,⧝ā§Ŧā§­,⧍⧝ā§Ģ āĻāĻŦāĻ‚ āϏāĻžāχāύāĻĄ āϰ⧇āĻžā§āϜāϟāĻŋāĻ“ āĻāĻ•āχāĻ­āĻžāĻŦ⧇ ⧍'āϏ āĻ•āĻŽāĻĒā§āϞāĻŋāĻŽā§‡āĻ¨ā§āϟ āĻĢāĻ°ā§āĻŽā§āϞāĻž āĻĒā§āĻ°ā§Ÿā§‹āĻ— āĻ•āϰ⧇ āĻŦ⧇āϰ āĻ•āϰāĻž āϝāĻžā§ŸāĨ¤

Memory Allocation of Integer Data Type

  • The integer is a fundamental (āĻŽā§ŒāϞāĻŋāĻ•) data type in C programming language.
  • An integer variable can occupy either 2 bytes or 4 bytes of memory space, depending entirely on the underlying architecture of the machine.
  • Since 1 byte is equal to 8 bits, a 2-byte integer corresponds to 16 bits, whereas a 4-byte integer corresponds to 32 bits. A larger allocation size inherently implies that the variable can hold more substantial data content.

The sizeof Operator

  • To programmatically (āĻĒā§āϰ⧋āĻ—ā§āϰāĻžāĻŽāĻ—āϤāĻ­āĻžāĻŦ⧇) determine the exact memory size of a data type during execution, C provides the sizeof operator.
  • It is crucial to note that sizeof is a unary operator (āĻāĻ•āĻ• āĻ…āĻĒāĻžāϰ⧇āϟāϰ) and not a function, despite its functional looking syntax.
  • If the system architecture allocates 4 bytes for an integer, evaluating sizeof(int) within a printf function will output the value 4.

Concept of Range

  • The term range refers to the defined upper and lower limits (āϏ⧀āĻŽāĻž) of a specific set of data.
  • For instance, in a data set containing {0, 1, 2, 3, 4}, the minimum value is 0 and the maximum value is 4, which establishes a definitive range from 0 to 4. No elements smaller than 0 or larger than 4 can exist within this boundaries.

Decimal Number System

  • Evaluating integer ranges requires a prerequisite (āĻĒā§‚āĻ°ā§āĻŦāĻļāĻ°ā§āϤ) comprehension of the Decimal number system.
  • This system is human-understandable and is formally called a base 10 number system, meaning it possesses a digit range strictly from 0 to 9.
  • For example, the number 568 is parsed by multiplying each constituent digit by its respective place values (āĻ¸ā§āĻĨāĻžāύ⧀āϝāĻŧ āĻŽāĻžāύ) starting from the rightmost end (\(8 \times 10^0 = 8\), \(6 \times 10^1 = 60\), \(5 \times 10^2 = 500\)), and adding them up to compute the final result of 568.

Binary Number System

  • Computers cannot interpret the decimal configuration; instead, they operate on the Binary number system, which is a base 2 number system containing only two digits: 0 and 1.
  • To convert a 4-bit binary sequence like 1100 into its decimal equivalent, each digit is multiplied by its base-2 place values (\(2^0, 2^1, 2^2, 2^3\)) from right to left. The summation process is: \((0 \times 1) + (0 \times 2) + (1 \times 4) + (1 \times 8) = 12\).

Range of a 4-bit Data Representation

  • For any standard 4-bit allocation, the minimum value is 0 (when all positions are 0) and the maximum value is 15 (when all positions are 1).
  • To efficiently calculate the maximum unsigned value for larger bit widths without manual expansion, the mathematical formula \(2^n - 1\) is highly handy (āωāĻĒāϝ⧋āĻ—ā§€). Substituting \(n = 4\) bit positions yields \(2^4 - 1 = 15\), defining the range from 0 to 15.

Comprehensive Integer Range Specifications

  • 2-Byte Integers (16 bits): On systems supporting 2-byte allocations, the total Unsigned range spans from 0 to 65,535 based on the formula \(2^{16} - 1\).
  • Signed Representations: To represent negative values alongside positive values, systems use signed magnitude, 1's complement, or 2's complement representations.
  • 2's Complement Range: Most modern computer systems exclusively utilize the 2's complement representation, which defines its boundaries using the formula: \(-2^{n-1}\) to \(+2^{n-1} - 1\). For a 16-bit space (\(n=16\)), the mathematical evaluation establishes a signed range from \(-32,768\) to \(+32,767\).
  • 4-Byte Integers (32 bits): On modern machines supporting 4-byte allocations, the Unsigned range expands significantly from 0 to 4,294,967,295, and the corresponding signed limit is obtained symmetrically by applying the same 2's complement limits.

Ref: Fundamental Data Types − Integer (Part 1)