Types of Integers
Integers can be broadly classified into three categories: positive integers, negative integers, and zero.
- Positive Integers: These are integers greater than zero. Examples include 1, 2, 3, and so on.
- Negative Integers: These are integers less than zero. Examples include -1, -2, -3, and so on.
- Zero: This is the integer that represents the absence of quantity or magnitude.
Properties of Integers
Integers have several properties that make them useful in mathematics and real-world applications.
Commutative Property: The commutative property of integers states that the order of addition or multiplication does not change the result. For example, 3 + 5 = 5 + 3 and 4 × 6 = 6 × 4.
Associative Property: The associative property of integers states that the order in which we add or multiply integers does not change the result. For example, (3 + 4) + 2 = 3 + (4 + 2) and (5 × 6) × 3 = 5 × (6 × 3).
Operations with Integers
Integers can be added, subtracted, multiplied, and divided, just like other whole numbers.
Adding Integers: When adding two positive integers, we simply add their values. For example, 5 + 7 = 12.
Subtracting Integers: When subtracting two positive integers, we subtract their values. For example, 7 - 5 = 2.
Multiplying Integers: When multiplying two positive integers, we multiply their values. For example, 5 × 7 = 35.
Real-World Applications of Integers
Integers have numerous applications in various fields, including mathematics, science, engineering, and finance.
Mathematics: Integers are used in various mathematical operations, such as addition, subtraction, multiplication, and division.
Science: Integers are used to measure physical quantities, such as temperature, time, and distance, which are expressed in units of measurement.
Engineering: Integers are used to design and develop systems, such as electronic circuits, mechanical systems, and software applications.
Integer Representation in Computing
Integers can be represented in various ways in computing, including binary, decimal, and hexadecimal.
Binary Representation: In binary representation, integers are represented using only two digits: 0 and 1.
Decimal Representation: In decimal representation, integers are represented using digits from 0 to 9.
Hexadecimal Representation: In hexadecimal representation, integers are represented using digits from 0 to 9 and letters from A to F.
| Integer | Binary Representation | Decimal Representation | Hexadecimal Representation |
|---|---|---|---|
| 10 | 1010 | 10 | A |
| 20 | 10100 | 20 | 14 |
| 30 | 11110 | 30 | 1E |
Integer Operations in Programming
Integer operations are performed differently in programming languages, depending on the language and its syntax.
Arithmetic Operations: In programming languages, integer arithmetic operations are performed using operators like +, -, *, /, and %.
Bitwise Operations: In programming languages, bitwise operations are performed using operators like &, |, ^, ~, and <<.
- AND (&): The AND operator performs a binary operation on two integers, resulting in an integer where each bit is set to 1 only if both corresponding bits in the operands are 1.
- OR (|): The OR operator performs a binary operation on two integers, resulting in an integer where each bit is set to 1 if either corresponding bit in either operand is 1.
- XOR (^): The XOR operator performs a binary operation on two integers, resulting in an integer where each bit is set to 1 if corresponding bits in the operands are different.
- NOT (~): The NOT operator performs a unary operation on an integer, resulting in an integer where each bit is inverted.
- LEFT SHIFT (<<): The LEFT SHIFT operator performs a binary operation on an integer, resulting in an integer where the bits are shifted to the left by the specified number of places.
Integer Overflow: In programming languages, integer overflow occurs when an integer value exceeds its maximum limit, causing it to wrap around to a small value.
Integer Underflow: In programming languages, integer underflow occurs when an integer value goes below its minimum limit, causing it to wrap around to a large value.