Shop OBEX P1 Docs P2 Docs Learn Events
Extracting numbers from base 10 — Parallax Forums

Extracting numbers from base 10

James LongJames Long Posts: 1,181
edited 2007-04-08 06:28 in Propeller 1
I have a integer that is 4 places (ie, 1234)

I would like to extrapolate the lower two digits in decimal format.

I've scratched my head how to do this........without a large amount of instructions.· (ie.....only get 34 from the above number)

Anyone know of a simple method to extract the information with out a large number of calls.

It would be of great help,

James L

Comments

  • T ChapT Chap Posts: 4,198
    edited 2007-04-08 01:12
    If you are sending a string from the Full Dup Object, doesn't it break up an integer into each byte value first and send each decimal as a separate ascii string ? Maybe there is a clue in that object if you can get the number into a string format, and choose the numbers out of the string that you want.

    Post Edited (TChapman) : 4/8/2007 3:03:26 AM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-08 04:11
    James,

    I couldn't tell if you wanted each digit seperately or just the last two digits.

    For the latter: x // 100 returns the remainder of a number divided by 100, or the last two numbers.

    For the former: x // 10 to get the ones, then (x // 100) / 10·or (x / 10) // 10 to get the tens digit. If you want the result in ASCII for display purposes add $30 to each value.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • James LongJames Long Posts: 1,181
    edited 2007-04-08 06:22
    I couldn't tell if you wanted each digit seperately or just the last two digits.

    For the latter: x // 100 returns the remainder of a number divided by 100, or the last two numbers.

    For the former: x // 10 to get the ones, then (x // 100) / 10·or (x / 10) // 10 to get the tens digit. If you want the result in ASCII for display purposes add $30 to each value.

    Ok...let me make sure I have this right.....If I have an integer of 3456...I can:

    (assuming x := 3456)

    x=//100

    and I will get back

    56

    That is cool.....didn't know the // worked like that.

    Thanks.....

    James L
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-08 06:25
    It would be x //= 100, but yes thats how the modulo operator works.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • James LongJames Long Posts: 1,181
    edited 2007-04-08 06:28
    Paul said...
    It would be x //= 100, but yes thats how the modulo operator works.
    Yep....typo's they are not fun in Spin.....chased one around for a while trying to figure out what I had done wrong.

    Thanks.....that is exactly what I needed.....I read that in the manual.....but it escaped me.

    Thanks again......that will really help alot.

    James L
Sign In or Register to comment.