Thread: How do you represent non-integer base numbers?

  1. #1
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812

    How do you represent non-integer base numbers?

    Hi there,

    Here's a maths one...

    We are all used to base-n numbers, where n is an integer, i.e. binary, octal hex etc.

    But how on Earth do you represent a number where n is non-integer. I.e. a number represented in the base of pi? I can understand the concept (well, I think), but how do you write down such a number? What symbols would you use? Can you represent it?

    Cheers
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  2. #2
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    number vrepresented on base of PI
    PI is not integer
    I wish to ask you do you need to know how? .. i mean do you need that on a task or you just curious??

    what i ve known that base 10 have been presented because when counting was discovered .. man started counting using his hand fingers where when we use computer and as a digital equipment it uses 0 and 1 so it's base 2
    but i cant find an application used by making base(22/7)

    the main problem facing us that what are the digits of PI on base16(Hexa) for example the digits are 0 1 2 3 4 5 6 7 8 9 A B C D E F and octal 0 1 2 3 4 5 6 7 and so on where the digits representing the number of base n are n-1 digits so what about base 3.14 is it going to be of 2.14 digits
    it's not valid man

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Simply put you couldn't display the number. Reason is because each base has n number of different symbols for each position. You wouldn't be able to have a partial symbol without creating a new symbol.

    Lets say you wanted to have a PI base though. Well you could factor out the PI (in the number and in the base) and convert the remainder. So lets say I wanted to display 16 times pi in a 2 pi base.

    well it would be: 10000(2pi)
    Last edited by Thantos; 04-02-2004 at 06:48 PM.

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Yeah, a base PI system might be convienent for representing multiples of PI, but it'd be really ugly for anything else.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #5
    The C-er
    Join Date
    Mar 2004
    Posts
    192

    Thoughts

    The place digits would work the same as any other system.

    like this:

    pi^3 pi^2 pi^1 pi^0 . pi^-1 pi^-2

    Note the PICIMAL POINT !

    The problem comes with the symbols chosen to represent each digit, because they would have to represent irrationals such that each digit x would be in the range 0<=x <= (pi-1).

    So you would need an infinite uncountable number of symbols for each digit.

    But if you have infinite precision for each digit, then you only need one to represent any number ! - so you get nowhere.

    Really you should only need pi different types of digit - so if you must have descrete quantities you would have 4 symbols.

    I propose these symbols.

    0
    1
    2
    P =pi-1

    Using this system the number 120P.1

    would be 1*pi^3 + 2*pi^2 + 0*pi^1 + (pi-1)*pi^0 + 1*pi^-1

    = 31.006 + 19.739 + 0 + 2.142 + 0.318 (to 3 dp)

    = 53.205 (approx)


    the number pi would be simply

    10 (of course)

    The only problem that I can see (there may be others) is that for each number, there may be more than one representation - because we have 4 symbols for each digit rather than 3.14159.....

    I think I'll stick to hex !

    Anyone fancy writing a conversion program?

    Convert Decimal to PINARY

  6. #6
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Thanks for the replies and to Jez.

    >Anyone fancy writing a conversion program?

    Well I'm thinking about it. But, still have no idea on how to represent such a conversion.

    I found this in my travels, if anyone's interested. It describes representing binary in base 26 (i.e. A to Z) and the probabilities of finding any string (i.e. the Bible) somewhere within the digits of PI.

    http://users.aol.com/s6sj7gt/picode.htm

    Good stuff!
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well its not extremely accurate but its close enough. I tried all the standard methods of base conversions but the only one that didn't have the trouble of converting floats to ints was the subtraction method.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define PI 3.14159265358989323846
    
    float getbase(float);
    
    int main(void)
    {
      float base;
      char out[50];
      float num = 4;
      int count=0, val=0, dec=0;
    
      printf("%f in base 10 is equivlent to approximatly:\n", num);
    
      base=getbase(num);
    
      while ( count < 49  && num > 0.0 )
      {
        if ( base < 1.0 && dec == 0)
        {
          dec = 1;
          out[count]='.';
          count++;
        }
        val = 0;
        while ( num >= base )
        {
          num -= base;
          val ++;
        }
        out[count] = '0' + val;
        base /= PI;
        count++;
      }
    
    
      out[count]='\0';
    
      printf("%s in base PI\n", out);
    
    
      return 0;
    }
    
    float getbase(float limit)
    {
      float num=PI;
    
      while ( num < limit )
        num *= PI;
    
      return num;
    }
    Last edited by Thantos; 04-05-2004 at 11:54 AM.

  8. #8
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    What's the problem with using base 10 numbers? I love those...

    So easy to use, no wonder they're number one...

    Gah. AOL.

  9. #9
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >What's the problem with using base 10 numbers? I love those...

    They're only easy because you were taught as a child to use them. If you were taught HEX or base 5, it would be just as natural.

    In some cases, i.e. programming, it is easier to use a different base (i.e. HEX).

    Likewise, in certain mathematical problems, it would be convenient (I guess) to use something more exotic, like base PI or base e. Well, I say 'I guess', but I'm not pouring over pages of equations myself at the moment, so can't think of a specific example.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  10. #10
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    if your flying away from the earth at the speed of light and you switch on your headlights, what happens?
    "Assumptions are the mother of all **** ups!"

  11. #11
    The Earth is not flat. Clyde's Avatar
    Join Date
    Mar 2002
    Posts
    1,403
    It takes you an infinite amount of time to switch them on.

    -How is this on topic?
    Entia non sunt multiplicanda praeter necessitatem

  12. #12
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Well, what you are really looking at with representing number in a base b is an infinite dimensional vector space over R generated by the multiplicative powers of the base, b, which is isomorphic to those generated by the powers of 10. So, certainly, you can write any number m = a[m] * b^m + a[m - 1] * b ^ (m - 1) + ... + a[1] * b + a[0] as long as the span of the set of multiplicative powers spans R (reals). It isn't entirely clear what symbols you'd want to use, however. For example, looking at base 10, take the number 35. We choose to represent this as 3 * 10 + 5, but it could equally well be written as 3.5 * 10 + 0. We choose to take our coefficients from the integer ring Z, where the basis lies.

    As far as e and pi, neither of those are even algebraic over Q, so it stands to reason that trying to make sense of any basis made from these elements is not particularly easy (or even useful).
    Last edited by Zach L.; 04-07-2004 at 09:08 PM.

  13. #13
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Sure sure, give me no love for my program

    <cries>

  14. #14
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >As far as e and pi, neither of those are even algebraic over Q, so it stands to reason that trying to make sense of any basis made from these elements is not particularly easy (or even useful)

    I see & take your point. Thanks.

    Oh, and switching on head lights. You cannot travel at the speed of light. However, if you were travelling very close to the speed of light (but not actually at it), then I guess when you turn your head lights on, the light would travel away from you at the speed of light (as it always does). However, I don't think you would see much, cos anything that isn't moving close to your own speed will 'perceive' your headlight beams as gamma-rays.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  15. #15
    The C-er
    Join Date
    Mar 2004
    Posts
    192

    Well, what you are really looking at with representing number in a base b is an infinite dimensional vector space over R generated by the multiplicative powers of the base, b, which is isomorphic to those generated by the powers of 10. So, certainly, you can write any number m = a[m] * b^m + a[m - 1] * b ^ (m - 1) + ... + a[1] * b + a[0] as long as the span of the set of multiplicative powers spans R (reals).
    Damn! I knew someone who knows what they're talking about would come and spoil our fun!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  2. Replies: 1
    Last Post: 03-26-2006, 03:44 PM
  3. Integer power
    By Sure in forum C Programming
    Replies: 3
    Last Post: 06-10-2005, 03:43 PM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. converting numbers from one base to another
    By partnole in forum C++ Programming
    Replies: 4
    Last Post: 10-04-2001, 12:29 PM