Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #163530
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: ot: on a base being a power of another |
| Followup-To | comp.programming |
| Date | 2021-11-20 22:22 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87wnl2h3gc.fsf@bsb.me.uk> (permalink) |
| References | <86mtlyh6vu.fsf@levado.to> |
Followups directed to: comp.programming
Meredith Montgomery <mmontgomery@levado.to> writes: > This is totally not C related, but I think you guys master the subject, > so perhaps it isn't so off-topic. Yes, it really is off-topic! Since you are thinking about algorithms, comp.programming is probably the closest fit. I've set followup-To. Maybe a good thread there will revive that group. > It's of course very useful to know how to convert numerals from one base > to another when we deal with C programming. I can convert from any base > to any base. What I'm trying to understand now is why it is so easy to > go from, say, base two to base eight or base sixteen or, say, base three > to base nine. When the two bases are positive integer powers of some common number, the conversion is simply a matter of grouping digits. You clearly get this as you go on to give explicit examples, so I am not sure why you are asking why it's easy. > To go from base two to base sixteen, you take four digits in base two > and map them to base sixteen --- from right to left. (We can, say, > left-pad the last group of digits if they don't have four digits.) I > notice that 2^4 = 16 and it is the exponent here that dictates how many > digits I grab each time --- from right to left. > > So if I need to convert base nine to base three, I'll take each digit > (from right to left) and replace it with its corresponding base three > digits, making to sure to always write them as two digits because > 3^2 = 9. <cut> > Why does this work? I don't know. I don't know what sort of answer that question needs. It seems obvious to me that groups of k > 1 base b digits are just the digits in base b^k. <cut> > Definition. To express a number N in a certain base b, we need to > find the coefficients a0, a1, ..., ak such that > > N = ak b^k + a(k-1) b^(k-1) + ... + a0 b^0. You probably intended to say more, though this definition is interesting in it's own right. For example, using b=10, N=20 can be written with a0 = 20 a0 = 0, a1 = 2 a0 = -10, a1 = 3 and so on. Also, your definition permits b to be something other than a positive integer. Base e, anyone? Base -2? And permitting (as you do by default) the digits to be rational or even irrational numbers is also interesting! > Can you solve this problem or point me somewhere? I'm not sure what the problem is. You started by saying you can convert between any two bases, but maybe you meant "one can convert" and you don't know a general algorithm to do it. Is that the problem you are asking about? -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ot: on a base being a power of another Meredith Montgomery <mmontgomery@levado.to> - 2021-11-20 18:08 -0300
Re: ot: on a base being a power of another Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-11-20 22:22 +0000
Re: ot: on a base being a power of another Bart <bc@freeuk.com> - 2021-11-20 22:27 +0000
Re: ot: on a base being a power of another James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-11-20 18:08 -0500
Re: ot: on a base being a power of another Meredith Montgomery <mmontgomery@levado.to> - 2021-11-23 15:43 -0300
Re: ot: on a base being a power of another Bart <bc@freeuk.com> - 2021-11-23 19:57 +0000
Re: ot: on a base being a power of another "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2021-11-23 16:53 -0800
Re: ot: on a base being a power of another Meredith Montgomery <mmontgomery@levado.to> - 2021-11-24 11:14 -0300
Re: ot: on a base being a power of another Manfred <noname@add.invalid> - 2021-11-21 05:41 +0100
csiph-web