Re: Setting value of a class
From: JKop (NULL_at_NULL.NULL)
Date: 06/20/04
- Next message: Min-Koo Seo: "Does anyone has fixed size memory allocator code?"
- Previous message: valentin tihomirov: "Re: Java's performance far better that optimized C++"
- In reply to: Rolf Magnus: "Re: Setting value of a class"
- Next in thread: Jack Klein: "Re: Setting value of a class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 20 Jun 2004 14:39:47 GMT
Rolf Magnus posted:
> JKop wrote:
>
>> Consider the following platform:
>>
>> char = 8-bit
>>
>> short = 16-bit
>>
>> int = 32-bit
>>
>> long = 32-bit
>>
>>
>> The largest value possible for unsigned long is 4,294,967,295 = 4.29
>> billion approx.
>>
>> Now imagine you're some sort of census people and you're keeping track
>> of the population of the earth. You're going to want a 33-Bit Number.
>> You look around and you find a library that has a certain class that
>> gives you a 64- Bit number.
>> The following is heavily contrived... but just bare with me. So
>> here's
>> how the system will work.
>>
>> #include <superint.h>
>>
>> class Human
>> {
>> protected:
>>
>> static SixtyFourBitInt amount_humans = 0;
>>
>> public:
>> Human(void)
>> {
>> ++amount_humans; }
>>
>> ~Human(void)
>> {
>> --amount_humans; } };
>>
>> static SixtyFourBitInt Human::amount_humans;
>>
>>
>> This should all be fine and dandy... but how would one, or how does
>> one (to those who have experience with this) actually manually set its
>> value? Consider the following:
>>
>>
>> SixtyFourBitInt numbr;
>>
>> numbr = 5000000000;
>>
>> This won't compile obviously.
>>
>>
>>
>> Do you have to do something like the following?:
>>
>>
>> SixtFourBitInt numbr;
>>
>> numbr = 4000000000;
>>
>> numbr += 1000000000;
>>
>>
>> How exactly would you do it?
>
> That depends on the class you use. One way around (that is e.g. used in
> std::bitset) is to use a string:
>
> SixtyFourBitInt numbr("5000000000");
Yes, this works. But, I think it's dirty. Firstly, it's going into the realm
of even representing a number using digits, and in so-doing, specifiying a
radix and set of digits, ie. the decimal system and the digits, '0' through
'9'.
>
> Or it could be split up into two 32 bit parts, which would then best be
> specified as hex values:
>
> SixtyFourBitInt numbr(0x1, 0x2A05F200);
...but is this defined behaviour?? I myself may think of the number 25 being
represented in binary as:
0001 1001
But that doesn't mean the computer does!! I may store it backwards:
1001 1000
or topsy-turvy:
0011 1000
>
>> Another example, consider another class:
>>
>>
>> class InternationalPhoneNumber;
>>
>>
>> This class is going to (well..., wants to) use 4 bits for each digit,
>> 0 through 9. Obviously, at some stage, the programmer will want to set
>> the value of this beast. Would the following be the best course of
>> action?:
>>
>> InternationalPhoneNumber disneylands_number = "44990561002";
>>
>> And then just manipulate the string into 4 bits for each digit?
>
> I would use a string directly to store a phone number. This will make it
> possible to support special values like # and *, as well as separators
> like / and -. Also, you won't know how long the number will be. It
> might have 20 digits or 30 or even 40.
I want to explicitly limit an international phone number to being comprised
of just the digits 0 through 9.
Another thing, I want to conserve memory by using 4 bits as opposed to
the possible 8 bits used for a char.
And even with the 4 bits, I still have 6 combinations left over for the #
symbol or whatever.
Thanks for the input. Keep the suggestions coming!
-JKop
- Next message: Min-Koo Seo: "Does anyone has fixed size memory allocator code?"
- Previous message: valentin tihomirov: "Re: Java's performance far better that optimized C++"
- In reply to: Rolf Magnus: "Re: Setting value of a class"
- Next in thread: Jack Klein: "Re: Setting value of a class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|