Deutsch English Français Italiano |
<cb2050661d2b8a16560fd69cb2c5fe6d12eda5de@i2pn2.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: Richard Damon <richard@damon-family.org> Newsgroups: comp.lang.c Subject: Re: What is your opinion about unsigned int u = -2 ? Date: Fri, 9 Aug 2024 21:16:19 -0400 Organization: i2pn2 (i2pn.org) Message-ID: <cb2050661d2b8a16560fd69cb2c5fe6d12eda5de@i2pn2.org> References: <v8dfo9$1k7cg$1@dont-email.me> <pan$d2c8a$8c54ac9f$29a202e0$12c6ce86@invalid.invalid> <87bk2cecan.fsf@bsb.me.uk> <v8inds$2qpqh$1@dont-email.me> <v8iqnr$7l3c$1@news.xmission.com> <v8oha0$6935$2@raubtier-asyl.eternal-september.org> <v91157$3eui3$2@dont-email.me> <v930b2$4v1a$1@dont-email.me> <v95luq$9hos$1@raubtier-asyl.eternal-september.org> <v95mkf$unfr$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 10 Aug 2024 01:16:20 -0000 (UTC) Injection-Info: i2pn2.org; logging-data="2032647"; mail-complaints-to="usenet@i2pn2.org"; posting-account="diqKR1lalukngNWEqoq9/uFtbkm5U+w3w6FQ0yesrXg"; User-Agent: Mozilla Thunderbird Content-Language: en-US In-Reply-To: <v95mkf$unfr$1@dont-email.me> X-Spam-Checker-Version: SpamAssassin 4.0.0 Bytes: 2366 Lines: 23 On 8/9/24 2:19 PM, David Brown wrote: > On 09/08/2024 20:08, Bonita Montero wrote: >> Am 08.08.2024 um 19:47 schrieb David Brown: >> >>> Think about negating a value. For two's complement, that means >>> inverting each bit and then adding 1. For sign-magnitude, you >>> invert the sign bit. For ones' complement, you invert each bit. >> >> But with one's complement you have the same circuits for ading >> and substracting like with unsigned values. > > If you are trying to say that for two's complement, "a + b" and "a - b" > use the same circuits regardless of whether you are doing signed or > unsigned arithmetic, then that is correct. It is one of the reasons why > two's complement became the dominant format. > No, a two's complement subtractor needs to invert the second operand, and inject a carry into the bottom bit. A one's complement subtractor just need to invert the second operand. The fact that you want that carry input in the logic anyway for add-with-carry to make bigger additions, says that this doesn't really cost anything.