Question: I have the following DataSet on a SSRS report:

```
SELECT
  VariationCode.Code
  ,VariationCoding.Comment
  ,VariationCoding.SubmissionDate
  ,VariationCoding.Id
FROM
  VariationCode
  INNER JOIN VariationCoding
    ON VariationCode.Id = VariationCoding.VariationCodeId
WHERE VariationId = @VariationId

```

I am showing static headers on the left and data on the right which works fine but I'm struggling to group the results by ID and show them as a separate table per grouping.

Grouping the row by parent using VariationCoding.Id shows one table with no grouping at all. I suspect having the headers on the left is the problem since most solutions I've seen have the headers on top.

How can I show static headers on the left and group the results by VariationCoding.Id in such a way that each result will be displayed in a separate table?

Answer: 
n bits can represent 2n different values. (The first bit can have two values \* the second bit can have two values \* the third bit can have two values \* ...)

For example, 3 bits can form 23 = 8 different bit patterns, and thus up to 8 different values.

```
000
001
010
011
100
101
110
111

```

If each bit pattern represents an integer, then an n-bit integer can represent 2n different integers. For example,

* It could represent the integers from 0 to 2n-1 inclusively  
(because (2n-1) - (0) + 1 = 2n different values).

For example,

```
  000   0
  001   1
  010   2
  011   3
  100   4
  101   5
  110   6
  111   7

```
* It could represent the integers from -(2n-1) to 2n-1-1 inclusively  
(because (2n-1-1) - (-(2n-1)) + 1 = 2n different values).

For example,

```
  100  -4
  101  -3
  110  -2
  111  -1
  000   0
  001   1
  010   2
  011   3

```

You could assign any meaning to these values, but the previously stated ranges are the ones understood by twos'-complement machines for unsigned integers and signed integers respectively.[1]

---

1. On a [ones'-complement](https://en.wikipedia.org/wiki/Ones%27_complement) machine, there are two ways of writing zero (0000...00002 and 1000...00002), so the range is only -(2n-1-1) to 2n-1-1. I think all modern machines are [twos'-complement](https://en.wikipedia.org/wiki/Two%27s_complement) machines, though.
Where did you find this incorrect paragraph? It appears to be about 2's complement but has the `-1` in the wrong place.

For C implementations using one's complement or sign/magnitude signed integers, the range is symmetric around zero (with 2 bit patterns that both represent `0`, so the positive range and the negative range are the same size).

Basically nothing ever uses that these days, but the ISO C standard specifies that signed integers are binary and use either two's complement, one's complement, or sign/magnitude.

---

In [2's complement](https://en.wikipedia.org/wiki/Two%27s_complement) (nearly universal these days), the range of representable values using n bits is 
[- 2n-1 , 2n-1 - 1 ]. **One bit-pattern (all bits zero) represents the value zero**. Every bit has a place-value of `2^i`, except the final one which has a place value of `-2^(n-1)`.

The bit-pattern with all bits set represents `-1` because `sum(2^i, i=0..n-1)` is one less than `2^n`.

**With *only* the sign bit set, we get the most-negative number**: `-INT_MIN` is signed overflow (undefined behaviour) because it's not representable as an `int`; it requires a wider integer. Or with wrapping, `-INT_MIN = INT_MIN`. This is the "2's complement anomaly". <https://en.wikipedia.org/wiki/Two%27s_complement#Most_negative_number>

You can avoid widening if you're doing an absolute value operation: e.g.  

`unsigned abs = i >= 0 ? i : -(unsigned)i;`

(Converting a negative value to `unsigned` in C has well-defined behaviour of modulo-reducing until it's in the representable range. In C this is independent of the signed-integer encoding; what matters is the *value*. So `(uint8_t)-1` is *always* 255. For 2's complement it just copies the bit-pattern. For sign/magnitude or one's complement a C implementation would have to do some math to cast from signed to signed. Notice that I did this *before* negation, which means `0 - i` with the usual unsigned wrapping.)