Shop OBEX P1 Docs P2 Docs Learn Events
Conveting ASCI numbers — Parallax Forums

Conveting ASCI numbers

ArchiverArchiver Posts: 46,084
edited 2002-12-21 15:55 in General Discussion
I am getting serial information via the SERIN commands into my BS2
from my DVD7400 Pionneer. When asking for the frame numbers, I get
the numbers in a series of byte, one for each number. to read the
data, I had to make an array byte (serData(7))and then build the
string byte by byte. The problem is that my frame number is now a
string and I can not do any math manipulation on it. I need to
multiply it, divide it etc. Any idea of how to do this conversion?

Many thanks,

Al

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-12-21 06:24
    If you provide more details on how the data ends up in your string, many of
    us here can and will help you out. Essentially, though, you can get the
    decimal value of an ASCII digit by subracting "0" (decimal 48) from it.

    -- Jon Williams
    -- Parallax

    In a message dated 12/21/2002 12:20:17 AM Central Standard Time,
    brownstamp@y... writes:

    > I am getting serial information via the SERIN commands into my BS2
    > from my DVD7400 Pionneer. When asking for the frame numbers, I get
    > the numbers in a series of byte, one for each number. to read the
    > data, I had to make an array byte (serData(7))and then build the
    > string byte by byte. The problem is that my frame number is now a
    > string and I can not do any math manipulation on it. I need to
    > multiply it, divide it etc. Any idea of how to do this conversion?
    >
    > Many thanks,
    >
    > Al
    >



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-21 06:27
    In general if you number is in, say, a(0)..a(7) you might write:

    V=0
    For i=0 to 7
    v=v*10
    v=v+a(i)-"0"
    Next i


    You want to start at the "left" and work to the right. Of course, you
    could go backwards, stop on a terminating character, etc. The answer is
    in v.

    Hope that helps.

    Al Williams
    AWC
    * Easy RS-232 Prototyping
    http://www.al-williams.com/awce/rs1.htm


    >
    Original Message
    > From: brownstamp <brownstamp@y...> [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=h7ITyrDMceLEVa8ybVDfjNmaucEiR2QSYt9CoQPdbj6verfFO0j_2q3xm_vbZ-gC2ywDcFzkm2-F9g]brownstamp@y...[/url
    > Sent: Saturday, December 21, 2002 12:18 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Conveting ASCI numbers
    >
    >
    > I am getting serial information via the SERIN commands into my BS2
    > from my DVD7400 Pionneer. When asking for the frame numbers, I get
    > the numbers in a series of byte, one for each number. to read the
    > data, I had to make an array byte (serData(7))and then build the
    > string byte by byte. The problem is that my frame number is now a
    > string and I can not do any math manipulation on it. I need to
    > multiply it, divide it etc. Any idea of how to do this conversion?
    >
    > Many thanks,
    >
    > Al
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-21 06:44
    Thanks Jon and Al, always great help!

    I send the DVD player a status request in the form:
    serOut outPin,baud,[noparse][[/noparse]"?F",cr].
    I then get the return data via:
    serData var byte(7)
    serin inPin,baud, [noparse][[/noparse]STR serData\7]
    debug str serData

    what I get is a string with showing the frame no. in ASCI
    for "0054773" for example.

    I want to convert that into a real number. I sort of understand
    what Al suggested and I am about to try it out, but would like to
    also get your opinion. I am doing some very fast searching for
    frame numbers and would really like to have as little delay as
    possible in my code.

    many thanks for staying so late on a Friday night answering yet
    another novice's questions.

    Al Najjar






    --- In basicstamps@yahoogroups.com, jonwms@a... wrote:
    > If you provide more details on how the data ends up in your
    string, many of
    > us here can and will help you out. Essentially, though, you can
    get the
    > decimal value of an ASCII digit by subracting "0" (decimal 48)
    from it.
    >
    > -- Jon Williams
    > -- Parallax
    >
    > In a message dated 12/21/2002 12:20:17 AM Central Standard Time,
    > brownstamp@y... writes:
    >
    > > I am getting serial information via the SERIN commands into my
    BS2
    > > from my DVD7400 Pionneer. When asking for the frame numbers, I
    get
    > > the numbers in a series of byte, one for each number. to read
    the
    > > data, I had to make an array byte (serData(7))and then build the
    > > string byte by byte. The problem is that my frame number is now
    a
    > > string and I can not do any math manipulation on it. I need to
    > > multiply it, divide it etc. Any idea of how to do this
    conversion?
    > >
    > > Many thanks,
    > >
    > > Al
    > >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-21 07:11
    What do those digits represent? Are they broken down into track, hours,
    minutes, seconds, frames? You may want to watch your player's display when
    you make the request so you can compare what it says to what you're getting.
    That will give you an idea of how you'll do your parsing later.

    -- Jon Williams
    -- Parallax


    In a message dated 12/21/2002 12:45:36 AM Central Standard Time,
    brownstamp@y... writes:

    > what I get is a string with showing the frame no. in ASCI
    > for "0054773" for example.
    >
    > I want to convert that into a real number. I sort of understand
    > what Al suggested and I am about to try it out, but would like to
    > also get your opinion. I am doing some very fast searching for
    > frame numbers and would really like to have as little delay as
    > possible in my code.



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-21 15:09
    these numbers represent the current frame number on the DVD. So if
    the number I am getting through the serial port to the BS2
    is "0012345" when I look on the screen of the TV, the frame number
    is 12345.

    I didn't understand (and I tried the little script from AL W.) to
    subtract "0" from the actual ASCI digit but that gives nothing.


    Al



    --- In basicstamps@yahoogroups.com, jonwms@a... wrote:
    > What do those digits represent? Are they broken down into track,
    hours,
    > minutes, seconds, frames? You may want to watch your player's
    display when
    > you make the request so you can compare what it says to what
    you're getting.
    > That will give you an idea of how you'll do your parsing later.
    >
    > -- Jon Williams
    > -- Parallax
    >
    >
    > In a message dated 12/21/2002 12:45:36 AM Central Standard Time,
    > brownstamp@y... writes:
    >
    > > what I get is a string with showing the frame no. in ASCI
    > > for "0054773" for example.
    > >
    > > I want to convert that into a real number. I sort of understand
    > > what Al suggested and I am about to try it out, but would like
    to
    > > also get your opinion. I am doing some very fast searching for
    > > frame numbers and would really like to have as little delay as
    > > possible in my code.
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-21 15:18
    One thing you might be able to do to speed things up is change the part
    that says v*10 to (v<<3)+(v<<1) which is the same as (v*8)+(v*2) =v*10
    but should be faster.

    However, you number will be too big for a single 16-bit integer. You
    probably need to convert to 3 digit "prefix" number and then a 4 digit
    "range" number. That's easy enough:

    V0=0
    V1=0

    For i=0 to 2
    V0=(v0<<3)+(v0<<1) ' v0=v0*10
    V0=serData(i)-"0"+V0
    Next

    For i=3 to 7
    V1=(v1<<3)+(v1<<1)
    V1=serData(i)-"0"+V1
    Next

    Now V0 would equal 5 and V1 would equal 4773. Since you know all of your
    numbers will be between $30 and $39, it might be faster to replace
    serData(i)-"0" with serData(i).Nib0. That might be faster, but only
    timing will tell for sure.

    Al Williams
    AWC
    * Floating point A/D
    http://www.al-williams.com/awce/pak9.htm




    >
    Original Message
    > From: brownstamp <brownstamp@y...> [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=FDtCvPjHRoWZUHLx0MDYnnFghyT0kss6BGt67JkKsEsHqUwBsYe0suJTiCW4xExNf4UG3n6bJbLr4Q]brownstamp@y...[/url
    > Sent: Saturday, December 21, 2002 12:45 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Re: Conveting ASCI numbers
    >
    >
    > Thanks Jon and Al, always great help!
    >
    > I send the DVD player a status request in the form:
    > serOut outPin,baud,[noparse][[/noparse]"?F",cr].
    > I then get the return data via:
    > serData var byte(7)
    > serin inPin,baud, [noparse][[/noparse]STR serData\7]
    > debug str serData
    >
    > what I get is a string with showing the frame no. in ASCI
    > for "0054773" for example.
    >
    > I want to convert that into a real number. I sort of understand
    > what Al suggested and I am about to try it out, but would like to
    > also get your opinion. I am doing some very fast searching for
    > frame numbers and would really like to have as little delay as
    > possible in my code.
    >
    > many thanks for staying so late on a Friday night answering yet
    > another novice's questions.
    >
    > Al Najjar
    >
    >
    >
    >
    >
    >
    > --- In basicstamps@yahoogroups.com, jonwms@a... wrote:
    > > If you provide more details on how the data ends up in your
    > string, many of
    > > us here can and will help you out. Essentially, though, you can
    > get the
    > > decimal value of an ASCII digit by subracting "0" (decimal 48)
    > from it.
    > >
    > > -- Jon Williams
    > > -- Parallax
    > >
    > > In a message dated 12/21/2002 12:20:17 AM Central Standard Time,
    > > brownstamp@y... writes:
    > >
    > > > I am getting serial information via the SERIN commands into my
    > BS2
    > > > from my DVD7400 Pionneer. When asking for the frame numbers, I
    > get
    > > > the numbers in a series of byte, one for each number. to read
    > the
    > > > data, I had to make an array byte (serData(7))and then build the
    > > > string byte by byte. The problem is that my frame number is now
    > a
    > > > string and I can not do any math manipulation on it. I need to
    > > > multiply it, divide it etc. Any idea of how to do this
    > conversion?
    > > >
    > > > Many thanks,
    > > >
    > > > Al
    > > >
    > >
    > >
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-21 15:23
    What gives you nothing? Try: debug hex serdata(0) and tell us what you
    get. If you get 30 then you have ASCII digits and serdata(0)-$30 (or
    -"0") will give you 0, 1, 2, etc. If you get 01 then they are not ASCII
    and you simply omit the -"0" and you should be good to go.

    Al Williams
    AWC
    * Floating point math for the Stamp, PIC, SX, or any microcontroller
    http://www.al-williams.com/awce/pak1.htm



    >
    Original Message
    > From: brownstamp <brownstamp@y...> [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=UhlVRk2Gu3a7kk78F-OajaYki5aMyxwRbS3Hfj1PAtDEe5siftjP0veLabQNG49HuI5lpXN0E3OkKq_SAA]brownstamp@y...[/url
    > Sent: Saturday, December 21, 2002 9:10 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]JUNK] [noparse][[/noparse]basicstamps] Re: Conveting ASCI numbers
    >
    >
    > these numbers represent the current frame number on the DVD. So if
    > the number I am getting through the serial port to the BS2
    > is "0012345" when I look on the screen of the TV, the frame number
    > is 12345.
    >
    > I didn't understand (and I tried the little script from AL W.) to
    > subtract "0" from the actual ASCI digit but that gives nothing.
    >
    >
    > Al
    >
    >
    >
    > --- In basicstamps@yahoogroups.com, jonwms@a... wrote:
    > > What do those digits represent? Are they broken down into track,
    > hours,
    > > minutes, seconds, frames? You may want to watch your player's
    > display when
    > > you make the request so you can compare what it says to what
    > you're getting.
    > > That will give you an idea of how you'll do your parsing later.
    > >
    > > -- Jon Williams
    > > -- Parallax
    > >
    > >
    > > In a message dated 12/21/2002 12:45:36 AM Central Standard Time,
    > > brownstamp@y... writes:
    > >
    > > > what I get is a string with showing the frame no. in ASCI for
    > > > "0054773" for example.
    > > >
    > > > I want to convert that into a real number. I sort of understand
    > > > what Al suggested and I am about to try it out, but would like
    > to
    > > > also get your opinion. I am doing some very fast searching for
    > > > frame numbers and would really like to have as little delay as
    > > > possible in my code.
    > >
    > >
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-12-21 15:55
    Thanks Al! you are a genius.....It works beautifuly and very fast.

    Al Najjar





    --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...> wrote:
    > What gives you nothing? Try: debug hex serdata(0) and tell us what
    you
    > get. If you get 30 then you have ASCII digits and serdata(0)-$30
    (or
    > -"0") will give you 0, 1, 2, etc. If you get 01 then they are not
    ASCII
    > and you simply omit the -"0" and you should be good to go.
    >
    > Al Williams
    > AWC
    > * Floating point math for the Stamp, PIC, SX, or any
    microcontroller
    > http://www.al-williams.com/awce/pak1.htm
    >
    >
    >
    > >
    Original Message
    > > From: brownstamp <brownstamp@y...> [noparse][[/noparse]mailto:brownstamp@y...]
    > > Sent: Saturday, December 21, 2002 9:10 AM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]JUNK] [noparse][[/noparse]basicstamps] Re: Conveting ASCI numbers
    > >
    > >
    > > these numbers represent the current frame number on the DVD. So
    if
    > > the number I am getting through the serial port to the BS2
    > > is "0012345" when I look on the screen of the TV, the frame
    number
    > > is 12345.
    > >
    > > I didn't understand (and I tried the little script from AL W.) to
    > > subtract "0" from the actual ASCI digit but that gives nothing.
    > >
    > >
    > > Al
    > >
    > >
    > >
    > > --- In basicstamps@yahoogroups.com, jonwms@a... wrote:
    > > > What do those digits represent? Are they broken down into
    track,
    > > hours,
    > > > minutes, seconds, frames? You may want to watch your player's
    > > display when
    > > > you make the request so you can compare what it says to what
    > > you're getting.
    > > > That will give you an idea of how you'll do your parsing later.
    > > >
    > > > -- Jon Williams
    > > > -- Parallax
    > > >
    > > >
    > > > In a message dated 12/21/2002 12:45:36 AM Central Standard
    Time,
    > > > brownstamp@y... writes:
    > > >
    > > > > what I get is a string with showing the frame no. in ASCI
    for
    > > > > "0054773" for example.
    > > > >
    > > > > I want to convert that into a real number. I sort of
    understand
    > > > > what Al suggested and I am about to try it out, but would
    like
    > > to
    > > > > also get your opinion. I am doing some very fast searching
    for
    > > > > frame numbers and would really like to have as little delay
    as
    > > > > possible in my code.
    > > >
    > > >
    > > >
    > > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    > > Subject and Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    > >
    > >
    > >
    > >
Sign In or Register to comment.