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: 
For an unsigned integer type, the value -1 is **out of range** and cannot be represented in a variable of that type. If you try to assign -1 to an `unsigned int` a **conversion** occurs according to the rules of the C standard.

The conversion of a signed value to an unsigned integer type is specified in section 6.3.1.3p2 of the [C standard](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf):

> 
> Otherwise, if the new type is unsigned, the value is 
>  converted by repeatedly adding or subtracting one more than 
>  the maximum value that can be represented in the new type
>  until the value is in the range of the new type.60
> 
> 
> ...
> 
> 
> 60) The rules describe arithmetic on the mathematical value, not the value of a given type of expression
> 
> 
> 

Assuming as in your example that `unsigned int` has a value range of 0 to 4,294,967,295 the value -1 is converted by adding -1 + 4,294,967,296 = 4,294,967,295. Note that this conversion happens regardless of how negative numbers are represented on the given system. It is the same for two's complment, ones' compliment, or sign-and-magnitude.

Note that this means that the representation of the converted value need not be the same as the representation of -1.

Using a 4-bit type as an example, converting the value -1 to an unsigned type results in the value 15. The representation of these numbers is as follows:

```none
                sign-and magnitude    ones' complement   two's complement
  -1   (signed)               1001                1110               1111
  15 (unsigned)               1111                1111               1111

```

While in the two's complement case the result of the conversion keeps the same representation, it changes in the other two cases. For one's complement the representation of -1 is the same as for 14, and for sign-and-magnitude the representation of -1 is the same as for 9.

So what other answers have described regarding two's complement is most likely how those implementations do it (i.e. reinterpreting the representation of -1 as an unsigned value), however from the perspective of C language as an abstract machine what I've described is the only correct way of performing this conversion.
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.)