C-style integers = integers with a fixed possible range of values and the corresponding rollover -- that is, if you get a result too big to be stored in that fixed size, it rolls over from the lowest possible value.

Ruby doesn't implement that limitation. It implements integers through Fixnum and Bignum. The latter is unbounded. The former is bounded but (per the linked doc) automatically converted to the latter if it would exceed its bounds.

Even if it did, it's still useful as an exercise: get a class to respond to addition, etc operations the same way that a C integer would. (And still something most participants will have trouble with.)

Hmm, interesting! Maybe the simplest approach would be to just implement a class with 16 (or 32, whatever) booleans, and do the underlying bit-pattern math. Then on printing, interpret as powers of two, or two's-complement, or whatever you like.

More "Stupid" Questions

by NancyLebovitz 1 min read31st Jul 2013498 comments


This is a thread where people can ask questions that they would ordinarily feel embarrassed for not knowing the answer to. The previous "stupid" questions thread went to over 800 comments in two and a half weeks, so I think it's time for a new one.