Shop OBEX P1 Docs P2 Docs Learn Events
Prob'ly a dumb question — Parallax Forums

Prob'ly a dumb question

kq6fkq6f Posts: 5
edited 2006-09-22 02:22 in BASIC Stamp
This seems pretty trivial but I haven't figured out how to do it.

I want to take a byte (value = 0 to 255), convert it to three decimal digits, then parse each digit into a byte.

Example:··byte1 value = 127
············· digit 1 = 1
············· digit 2 = 2
············· digit 3 = 7

·············· byte2 value = 1
·············· byte3 value = 2
·············· byte 4 value = 7

Can anybody help, please?
·

Comments

  • MikeKMikeK Posts: 118
    edited 2006-09-20 03:07
    byte2 = byte1 / 100
    byte3 = byte1 / 10 // 10
    byte4 = byte1 // 10

    / is integer division
    // is modulo
  • kq6fkq6f Posts: 5
    edited 2006-09-20 04:54
    Works perfectly!

    Thanks a million, MikeK..

    kq6f
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-09-20 05:20
    alternaively, check out the DIG operator,
    byte1 - 127
    byte2 = byte1 DIG 2 ' 1
    byte3 = byte1 DIG 1 ' 2
    byte4 = byte1 DIG 0 ' 7

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • kq6fkq6f Posts: 5
    edited 2006-09-20 14:56
    Many thanks, Tracy. I like your solution the best.

    Rod Brink, kq6f
  • SuperwormsSuperworms Posts: 118
    edited 2006-09-20 19:03
    no question is a dumb question

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Equipped with his 5 senses, man explores the world around and calls his adventure science
    ·
    -Edwin Hubble
    ·
  • Mike onlyMike only Posts: 15
    edited 2006-09-21 07:48
    I'm newbie in programming and have a question : I have BS2 module and want to start programming BASIC Stamp, but I don't have Parallax board. So I create my own circuits and cable to be connected to PC serial port. My question is, can I use the serial programming cable from scribbler robot? When I use a Parallax development board, I can not use "null modem" cable, is it the same case, when I make my own serial port? (Basic Stamp Reference Manual). Thank you for your help.

    Mike only
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-09-21 11:25
    Mike -

    You need a straight through cable, not a "null modem" cable to program any of the PBASIC Stamps. There is no reason why you can't make your own programming cable using the instructions found in the PBASIC Programming and Reference Manual. That manual can be found on the Parallax web site in the Downloads Section.

    Regards.

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Mike onlyMike only Posts: 15
    edited 2006-09-22 02:22
    Thank you for your informationcool.gif

    Mike only
Sign In or Register to comment.