Xref: utzoo comp.lang.c++:11505 comp.std.c++:578 Path: utzoo!dciem!nttor!contact!egr From: egr@contact.uucp (Gordan Palameta) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Re: Add-with-carry operator Message-ID: <1991Feb7.013620.28671@contact.uucp> Date: 7 Feb 91 01:36:20 GMT References: <1991Feb3.202530.14874@julius.cs.uiuc.edu> Organization: Contact Public Unix BBS. Toronto, Canada. Lines: 17 In <1991Feb3.202530.14874@julius.cs.uiuc.edu> zweig@cs.uiuc.edu (Johnny Zweig) writes: >In my work with the TCP/IP protocol suite, I have had to implement 16-bit >1's-complement arithmetic in a protable, efficient way for protocol processing >[rest of article omitted] To add-with-carry two 16-bit numbers in a portable way: - convert them to unsigned 32-bit (high word zero-filled) - add them to get a 32-bit result (normal addition, ie 2's complement) - take the upper 16 bits and lower 16 bits and add them together, getting a 32-bit result - do previous step again (important!) The lower 16 bits will be your answer (the upper 16 bits will be zero-filled). Try the tcp-ip newsgroup for any further info...