I am reading Kernighan and Ritchie, and honestly, I am not able to understand anything in the following sentence I encountered while reading:

Any integer is converted to a given unsigned type by finding the smallest non-negative value that is congruent to that integer,
modulo one more than the largest value that can be represented in the unsigned type.

Could anyone please clarify what congruent means here and try explaining to me what does this sentence exactly convey(if possible , with an example).

Thank you

P.S. I am referring to Appendix A Section A6.2 : Integral Conversions

Recommended Answers

All 2 Replies

The standard uses a simpler description:

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.

The standard uses a simpler description:

Okay.. got it to some extent. I will check the description given in the standard.
Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.