Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

OK, how do I make my own base number system in VB?

  • 30-11-2004 11:08PM
    #1
    Registered Users, Registered Users 2 Posts: 3,946 ✭✭✭


    This is the big thing i'm after. I want to be able to define, lets say the characters 0-9 and letters a-z as number, giving me a 36 base number system, if I assign a number to each character in vb, how do I tell it to use them? (Googling this gave me absolutely nothing)


Comments

  • Closed Accounts Posts: 82 ✭✭cyberbob


    are you ofay ( god knows how you spell that) with creating your own class structrures.
    its a lot of work to build a new number system .
    ( in c++ you can overload the +/-/*// operators ) .
    dont know if you can do that in VB , c++ is my mother tongue .
    even writing a simple add( a, b ) function would be a bitch though .


  • Registered Users, Registered Users 2 Posts: 3,946 ✭✭✭mp3guy


    could i not edit/expand on a hex code?


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    i'm not even sure if this will work... but in c could you not just do the following...
    int main()
    {
    'a'=1;
    'b'=2;
    'c'=3;
    .
    .
    .
    '1'=27;
    '2'=28;
    '3'=29;
    .
    .
    .
    .
    
    rest of code
    
    }
    
    then i suppose you could do stuff like 'a' + 'a' = 'b', and do stuff like that. Not sure if thats what you want, or even if what i said is right though :p
    


  • Closed Accounts Posts: 82 ✭✭cyberbob


    mp3guy wrote:
    could i not edit/expand on a hex code?
    i would have left well enough alone .
    the only way to expand on an existing type is with a class .
    you cant edit a builtin type .


  • Registered Users, Registered Users 2 Posts: 3,946 ✭✭✭mp3guy


    Post #4, yeah, that's what i want. How in vb do I tell it to convert to and from something like that?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,289 ✭✭✭kenmc


    i'm not even sure if this will work... but in c could you not just do the following...
    int main()
    {
    'a'=1;
    'b'=2;
    'c'=3;
    <snip>
    }
    

    no - that won't work.
    'a' is the ascii value of the letter a. It happens to be 97. The above code tells the compiler that
    97 = 1;
    98 = 2;
    etc.
    It will go mental, screaming at you from the rooftops and calling you all the names under the sun.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    There is a very easy way to do this. I actually wrote one before and it is on this forum*.

    The short end of it is...

    create a string with '012345679ABCDEF...etc', Each chacters location in the string is its base value. eg A is in the 10th position, F is 15th position. You just then use an instr to determine the value of a character.

    * Heh, went looking for it. I posted the same question as a teaser but doesn't appear to have my answer in it. Anyway thats the answer.


  • Registered Users, Registered Users 2 Posts: 3,946 ✭✭✭mp3guy


    thanks, so if vb knows the value of a character, how can i tell it to write numbers in that way?


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    mp3guy wrote:
    thanks, so if vb knows the value of a character, how can i tell it to write numbers in that way?

    The reverse way you got it from the string. Instr() = Character to number, mid() = number to character.


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    kenmc wrote:
    no - that won't work.
    'a' is the ascii value of the letter a. It happens to be 97. The above code tells the compiler that
    97 = 1;
    98 = 2;
    etc.
    It will go mental, screaming at you from the rooftops and calling you all the names under the sun.
    I thought the single quotes meant the letter a, so 'a' was referring to the letter a, not the ascii number that corresponds to a. hrmm, maybe i don't know as much as i thought :p


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,289 ✭✭✭kenmc


    I thought the single quotes meant the letter a, so 'a' was referring to the letter a, not the ascii number that corresponds to a. hrmm, maybe i don't know as much as i thought :p
    It does. sort of. ish. but it's a constant.
    all letters and characters are represented by numbers.
    so you can do stuff like this
    printf("%d\n", 'a');
    you will get 97.
    but if you do
    printf("%c\n", 'a');
    you will get a
    similarly you can do
    printf("%s\n", "a");
    and also get a

    It's all about representation really, and making it readable for us mere humans.


Advertisement