本文介绍了较大的整数在C较小的无符号的类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过K&放goint;河我有以下的197页上线的理解问题(第A6)

Can any body explain this in a bit detail.Thanks

解决方案

Let's take this bit by bit and from backwards:

2^(n) - 1.
2^n.
unsigned_val = signed_val % 2^n

Now, the why part: The standard does not mandate what bit representation is used. Hence the jargon. In a two's complement representation -- which is by far the most commonly used -- this conversion does not change the bit pattern (unless there is a a truncation, of course).

Refer to Integral Conversions from the Standard for further details.

这篇关于较大的整数在C较小的无符号的类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 16:04