๐ Inclusive Range Counting
The difference between two numbers is exclusive โ it doesnโt count the starting point.
To include both endpoints, you must add 1 if we took the negative difference or subtract 1 if we took the positive difference
The difference between two numbers is exclusive โ it doesnโt count the starting point.
To include both endpoints, you must add 1 if we took the negative difference or subtract 1 if we took the positive difference
To include both endpoints, you must add 1 if we took the negative difference or subtract 1 if we took the positive difference
๐งฉ Examples
Case 1: From 31 down to 24
[31, 30, 29, 28, 27, 26, 25, 24]- Difference:
31 - 24 = 7 - โ
Total count:
31 - 24 + 1 = 8
Case 2: Starting at 1, want 8 numbers
[1, 2, 3, 4, 5, 6, 7, 8]- Final number:
1 + 8 - 1 = 8 - โ
Range:
[1:8]โ total count = 8
๐ง Why This Matters in HDL and Indexing
โ Verilog slicing:
in[31:24] // โ
8 bits: 31 - 24 + 1
โ Looping:
for (i = 0; i < 8; i++) // โ
8 iterations
โ Array indexing:
mem[0:7] // โ
8 elements
Last updated on