views:

1484

answers:

7

Another question asked about determining odd/evenness in C, and the idiomatic (x & 1) approach was correctly flagged as broken for one's complement-based systems, which the C standard allows for.

Do systems really exist in the 'real world' outside of computer museums? I've been coding since the 1970's and I'm pretty sure I've never met such a beast.

Is anyone actually developing or testing code for such a system? And, if not, should we worry about such things or should we put them into Room 101 along with paper tape and punch cards...?

+2  A: 

I've never encountered a one's complement system, and I've been coding as long as you have.

But I did encounter a 9's complement system -- the machine language of a HP-41c calculator. I'll admit that this can be considered obsolete, and I don't think they ever had a C compiler for those.

Darron
+9  A: 

This all comes down to knowing your roots.
Yes, this is technically an old technique and I would probably do what other people suggested in that question and use the modulo (%) operator to determine odd or even. But understanding what a 1s compliment (or 2s compliment) is always a good thing to know. Whether or not you ever use them, your CPU is dealing with those things all of the time. So it can never hurt to understand the concept. Now, modern systems make it so you generally never have to worry about things like that so it has become a topic for Programming 101 courses in a way. But you have to remember that some people actually would still use this in the "real world"... for example, contrary to popular belief there are people who still use assembly! Not many, but until CPUs can understand raw C# and Java, someone is going to still have to understand this stuff.

And heck, you never know when you might find your self doing something where you actually need to perform binary math and that 1s compliment could come in handy.

Adam Haile
Thanks. Agree fully that you need to have learnt it, but you shouldn't worry about it - like 6-bit bytes, and how core memory works. BTW, it's "complement", not "compliment". One's compliment could be "that's a nice sign bit you're wearing today".
Roddy
I do a lot of interviewing of software engineers, using Steve Yegge's Five Areas (http://steve.yegge.googlepages.com/five-essential-phone-screen-questions), and you better believe that one of the areas is Bits and Bytes. If you want to be a good SDE, you must understand binary number systems, and ones and twos complement is part of that. I would hope that any decent Computer Science course covers this in the Computer organisation class(es).
jmglov
+4  A: 

We got off our last 1960's Honeyboxen sometime last year, which made it our oldest machine on site. It was two's complement. This isn't to say knowing or being aware of one's complement is a bad thing. Just, You will probably never run into one's complement issues today, no matter how much computer archeology they have you do at work.

The issues you are more likely to run into on the integer side are endian issues (I'm looking at you PDP). Also, you'll run into more "real world" (i.e. today) issues with floating point formats than you will integer formats.

sixlettervariables
I was on a site a few weeks ago that still had a few honeyboxen running! I was pretty shocked to see the machine powered up.
McPherrinM
+5  A: 

I work in the telemetry field and we have some of our customers have old analog-to-digital converters that still use 1's complement. I just had to write code the other day to convert from 1's complement to 2's complement in order to compensate.

So yes, it's still out there (but you're not going to run into it very often).

dongola7
+2  A: 

The CDC Cyber 18 I used back in the '80 was a 1s complement machine, but that's nearly 30 years ago, and I haven't seen one since (however, that was also the last time I worked on a non-PC)

James Curran
+3  A: 

RFC 791 p.14 defines the IP header checksum as:

The checksum field is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header. For purposes of computing the checksum, the value of the checksum field is zero.

So one's complement is still heavily used in the real world, in every single IP packet that is sent. :)

jmglov
Hmm, well... I was referring to one's complement as a means of representing negative integers, rather as a means of bitwise inversion, but you probably knew that. +1 for effort :-)
Roddy
A: 

what's the meaning of compensation of 1’s complement number into 2’s complement number?

Sangeetha