{"id":7413,"date":"2017-03-12T18:20:01","date_gmt":"2017-03-12T22:20:01","guid":{"rendered":"http:\/\/esr.ibiblio.org\/?p=7413"},"modified":"2017-03-13T07:27:14","modified_gmt":"2017-03-13T11:27:14","slug":"ones-complement-arithmetic-it-lives","status":"publish","type":"post","link":"http:\/\/esr.ibiblio.org\/?p=7413","title":{"rendered":"Ones-complement arithmetic: it lives!"},"content":{"rendered":"<p>Most hackers know how the twos-complement representation of binary numbers works, and are at least aware that there was an older representation called &#8220;ones-complement&#8221; in which you negated a binary number by inverting each bit.<\/p>\n<p>This came up on the NTPsec development list recently, with a question about whether we might ever have to port to a non-twos-complement machine. To my utter, gob-smacked astonishment, it turns out ones-complement systems still exist &#8211; though, thankfully, not as an issue for us.<\/p>\n<p>I thought I could just mumble something about the CDC 6600 and be done, but if you google &#8220;one&#8217;s-complement machines&#8221; you&#8217;ll find that Unisys still ships a series of machines with the brand &#8220;Clear-Path Dorado&#8221; (latest variant introduced 2015) that are emulations of their old 1100-series mainframes running over Intel Xeon hardware &#8211; and these have one&#8217;s-complement arithmetic.<\/p>\n<p>This isn&#8217;t a practical port blocker for NTPsec, as NTP will never run over the batch OS on these things &#8211; it&#8217;s about as POSIX-compatible as the Bhagavad-Gita. It&#8217;s just weird and interesting that ones-complement machines survive in any form at all.<\/p>\n<p>And a bit personal for me.  My father was a programmer at Univac in the 1950s and early &#8217;60s.  He was proud of his work.  My very first interaction with a computer ever was getting to play a very primitive videogame on the oscilloscope-based video console of a Univac 1108.  This was in 1968.  I was 11 years old, and my game machine cost $8M and took up the entire ground floor of an office building in Rome, Italy.<\/p>\n<p>Other than the 1100, the ones-complement machines Wikipedia mentions (LINC, PDP-1, and CDC6600) are indeed all long dead. There was a ones-complement &#8220;CDC Cyber&#8221; series as late as 1989, but again this was never going to implement POSIX.<\/p>\n<p>About other competitors to twos-complement there is less to say.  Some of them are still used in floating-point representations, but I can find no evidence that sign-magnitude or excess-k notation have been used for integers since the IBM 7090 in 1959.<\/p>\n<p>There&#8217;s a <a href=\"https:\/\/groups.google.com\/forum\/#!topic\/comp.std.c\/GlZeSxBnCW0\">comp.lang.std.c article from 1993<\/a> that argues in some technical detail that that a C compiler is not practical on ones-complement hardware because too many C idioms have twos-complement assumptions baked in. The same argument would apply to sign-magnitude and excess-k.<\/p>\n<p>UPDATE: It seems that Unisys is the graveyard of forgotten binary formats.  I have a report that its Clear-Path Libra machines, emulating an ancient Burroughs stack machine architecture, use sign-magnitude representation of integers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most hackers know how the twos-complement representation of binary numbers works, and are at least aware that there was an older representation called &#8220;ones-complement&#8221; in which you negated a binary number by inverting each bit. This came up on the NTPsec development list recently, with a question about whether we might ever have to port&hellip; <a class=\"more-link\" href=\"http:\/\/esr.ibiblio.org\/?p=7413\">Continue reading <span class=\"screen-reader-text\">Ones-complement arithmetic: it lives!<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-7413","post","type-post","status-publish","format-standard","hentry","category-software","entry"],"_links":{"self":[{"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/posts\/7413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7413"}],"version-history":[{"count":5,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/posts\/7413\/revisions"}],"predecessor-version":[{"id":7419,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/posts\/7413\/revisions\/7419"}],"wp:attachment":[{"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7413"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}