# Thread: MAths function with unsigned integer assigned a negative number

1. ## MAths function with unsigned integer assigned a negative number

I am trying to convert a C programme to a scrip basic language.

The C programme is fairly simple but produces unexpected results - it is the unxpected result that I would like to emulate with script basic.

I am hoping someone can explain the mechanism that the C programme is using to come up with the unexpected result, then I will try and put that in practice in script basic using the available functions.

The C programme:

Code:
```main()
{
unsigned int crc;

crc=-248625283;
printf("crc before div by 256 %d\n", crc);
crc=crc/256;
printf("crc after divide by 256 and assigned to an unsigned integer equals %d decimal \n", crc);

}```
Normally if you divide -248625283 by 256 you would get a result of -971192 (integer)
Similarly if you divide 248625283 by 256 you would get a result of 971192.

The programme above gives a result of 15806023 . I expect this is related to assigning a negative number to a unsigned integer. What I need to know is how to get this result (15806023) using basic maths functions.

I hope someone can help explain the mechanism that gives 15806023 when dividing -248625283 by 256.

2. Search the Web concerning "two's complement", "one's complement" and "sign and magnitude". This will give you information on how the negative value would be converted to be stored in an unsigned integer, and from there working out the division is easy.

3. Thanks laserlight it was the two's complement divided by 256. Fantastic, now to figure out how to do it in script basic.

4. Assuming int has 32 bits, putting -248625283 into an unsigned int gives you 4046342013. Divide that by 256 = 15806023.