OOT: negative numbers in any base
OOT: negative numbers in any base
- Subject: OOT: negative numbers in any base
- From: Michèle Garoche <email@hidden>
- Date: Wed, 7 Aug 2002 20:24:46 +0200
Hello,
Sorry for OOT.
Could someone tell me where I can find how the compiler build a negative
number? Some place on the web as I have no access to specialized
libraries, general (not only for binary numbers: I know how to do it),
and no too complicated as my math studies are far behind me:-)
A simple case: say I enter 1 in base 10, then I negate the number, the
result displayed is -1 as the compiler knows how to write it. Now I
switch to base 3 (not balanced ternary), how can I build the result (I
know how I can build the result for positive numbers, and I know the
limits).
I thought of that way to do it, but not sure if it's the right one:
1 - store the digits in an int variable - done
2 - translate the number into binary string - done
3 - translate the binary string into decimal - to do
4 - translate the decimal into x base string - done
Many thanks in advance,
Michhle
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.