我的VC ++文档声明这是一个补充操作符 ~0 = 0xFFFF又称所有位设置(将所有0'交换为1) 这意味着该位是: 0 = 0000 0000 0000 0000 0000 0000 0000 0000 = 0x00000000 ~0 = 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF 如果我只能操作4位那么: 一个补充表格给出: 0000 = + 0 1111 = -0 两个补充表格给出: 0000 = 0 1111 = -1 用C ++评估这个给出了-1,但我不明白我该如何计算 手动减去这个值的原因是什么? 有什么建议吗? 提前致谢!
解决方案~0 = 0xFFFF又称所有位设置(交换全0' s to 1) 这意味着该位是: 0 = 0000 0000 0000 0000 0000 0000 0000 0000 = 0x00000000 ~0 = 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF 如果我只能操作4位那么: 一个补充表格给出: 0000 = + 0 1111 = -0 两个补充表格给出: 0000 = 0 1111 = -1 评估这个C ++给-1,但是我不明白我怎样才能手动计算出这个的最小值以及为什么? 有什么建议吗? 提前致谢!
如果你想手动完成这项工作,请将每组数据转换为 十六进制数字。然后将十六进制转换为十进制。例如, 1010 1110 1010将是十六进制的AEA,即 (10次16立方)+(14次16平方)+14。 然后将每组四个转换为十六进制数
Kurt Krueckeberg写道: [...] 如果您想手动执行此操作,请将每组数据转换为十六进制数字。然后将十六进制转换为十进制。例如, 1010 1110 1010将是十六进制的AEA,即(10次16立方)+(14次16平方)+14。
实际上,它是 (10倍16平方)+(14倍16)+ 10. V
1111(或十六进制0xF)位实际上是-1,因为来自 VC ++。 但是〜是一个补码运算符,它应该给出答案: 1110这是-1的补码。那么什么时候进一步兑换 到 两个补充形式又名1111或0xF? 我不是真的理解~~可以给-1作为答案,当〜被称为 为一个补码运算符答案应该是1111那个'-0 in 一个补充。 " Jonny Iversen" <乔*********** @ gmail>在消息中写道 news:co ********* @ services.kq.no ... 我的VC ++文档声明这是一个补充运营商 ~0 = 0xFFFF又称所有位设置(将所有0'交换为1) 这意味着该位是: 0 = 0000 0000 0000 0000 0000 0000 0000 0000 = 0x00000000 ~0 = 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF 如果我只能操作4位则: 一个补充表格给出: 0000 = + 0 1111 = -0 两个补充表格给出: 0000 = 0 1111 = -1 在C ++中评估这个给出了-1,但我不明白我怎么能用b $ b来计算这个手动的减去值为什么? 有什么建议吗? 提前致谢!
My VC++ documentation state that this is the one complements operator ~0 = 0xFFFF aka all bits set (swapping all 0''s to 1) This means that the bit is: 0 = 0000 0000 0000 0000 0000 0000 0000 0000 = 0x00000000 ~0 = 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF If I could operate on only 4 bits then: One complements form gives: 0000 = +0 1111 = -0 Two complements forms gives: 0000 = 0 1111 = -1 Evaluating this in C++ gives -1, but i don''t understand how can I calculate the desimal value out of this manually and why? Any advice? Thanks in Advance!
解决方案 ~0 = 0xFFFF aka all bits set (swapping all 0''s to 1) This means that the bit is: 0 = 0000 0000 0000 0000 0000 0000 0000 0000 = 0x00000000 ~0 = 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF If I could operate on only 4 bits then: One complements form gives: 0000 = +0 1111 = -0 Two complements forms gives: 0000 = 0 1111 = -1 Evaluating this in C++ gives -1, but i don''t understand how can I calculate the desimal value out of this manually and why? Any advice? Thanks in Advance!If you want to do this by hand, convert each group of ones into a hexadecimal digit. Then convert the hexadecimal to decimal. For example, 1010 1110 1010 would be AEA in hexadecimal, which is (10 times 16 cubed)+(14 time 16 squared) + 14. Then convert each group of four into a hexadecimal number
Kurt Krueckeberg wrote: [...] If you want to do this by hand, convert each group of ones into a hexadecimal digit. Then convert the hexadecimal to decimal. For example, 1010 1110 1010 would be AEA in hexadecimal, which is (10 times 16 cubed)+(14 time 16 squared) + 14.Actually, it''s (10 times 16 squared) + (14 times 16) + 10. V
Following 1111 (or hexadecimal 0xF) bits is actually -1 as an result from VC++. But ~ is one complement operator which should give the answer: 1110 which is the one complement for -1. So when is this further converted to the two complements form aka 1111 or 0xF? I don''t really understand that ~0 can give -1 as the answer when ~ is said to be one complement operator the answer should have been 1111 that''s -0 in one complement. "Jonny Iversen" <jo***********@gmail> wrote in message news:co*********@services.kq.no... My VC++ documentation state that this is the one complements operator ~0 = 0xFFFF aka all bits set (swapping all 0''s to 1) This means that the bit is: 0 = 0000 0000 0000 0000 0000 0000 0000 0000 = 0x00000000 ~0 = 1111 1111 1111 1111 1111 1111 1111 1111 = 0xFFFFFFFF If I could operate on only 4 bits then: One complements form gives: 0000 = +0 1111 = -0 Two complements forms gives: 0000 = 0 1111 = -1 Evaluating this in C++ gives -1, but i don''t understand how can I calculate the desimal value out of this manually and why? Any advice? Thanks in Advance!更多推荐
补充或〜运算符
发布评论