How convert ASCII to char?


+ Reply to Thread
Results 1 to 7 of 7

Thread: How convert ASCII to char?876 days old

  1. #1
    Member Frizie's Avatar
    Join Date
    Apr 2003
    Posts
    174
    Thumbs Up
    Received: 2
    Given: 1
    Total Downloaded
    741.23 MB

    0 Not allowed!

    Lightbulb How convert ASCII to char?

    Les, it would be nice if Proton PIC Basic will get the instruction 'ASC' (like other Basic compilers) to convert the ASCII value from a character into a BYTE value.
    All other threads I've read here, none of them have a solution for this problem.

    VAL is not the solution, because it only can convert the characters 0...9 and a...f

    It works when I write directly:

    DIM
    Character AS BYTE
    Character = "M"
    PRINT Character



    The value 77 will be displayed, indeed the ASCII code from character 'M'.
    But I want to make an automatic routine for my application where I can put in a text and then do something like:

    DIM
    Text AS STRING * 15
    DIM Character AS BYTE
    DIM
    x AS BYTE

    Text = "Hello World"
    FOR x = 1 TO 11
    Character = MID$(Text, x, 1)
    PRINT AT 1, 1, DEC Character, " "
    DELAYMS 1000
    NEXT


    The example above doesn't work.
    It only gives '0' (zero) as result.
    That's why we need the instruction ASC, to solve the problem like this:

    Character = ASC(MID$(Text, x, 1))


    Or ís there another solution on this further great compiler (love to work with! )


    (I know the example hereabove is a useless example but the example must be small to make the point)

    Regards Frizie.
    picbasic.nl
    Ohm sweet Ohm: www.picbasic.nl

Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,167
    Thumbs Up
    Received: 96
    Given: 1
    Total Downloaded
    2.90 GB

    0 Not allowed!

    Default Re: How convert ASCII to char?

    MID$ will return a string, ASC cannot be applied to a string only to a character. When applied to a string it can only return the first character.

    A much simpler solution

    Code:
    Text = "Hello World"
    FOR x = 1 TO 11
    Character = Text[x]
    PRINT AT 1, 1, DEC Character, " "
    DELAYMS 1000
    NEXT
    JohnB

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    688
    Thumbs Up
    Received: 91
    Given: 2
    Total Downloaded
    4.62 GB

    0 Not allowed!

    Default Re: How convert ASCII to char?

    Better For x = 0 to 10
    73's de Alberto ea3agv

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,465
    Thumbs Up
    Received: 305
    Given: 145
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: How convert ASCII to char?

    An ASCII character is a byte value. ASCII "0" is the value 48, ASCII "1" is the value 49 etc... Whenever a standard byte variable is transmitted or displayed, and it holds a valid ASCII character, that's what will be displayed. Using the Dec modifier will never give an ASCII character because it will convert the byte value to its set of ASCII characters that make up the value.

    An ASC procedure isn't required when using a compiler that actually has real byte variables.

    For example:
    Code:
        Include "Amicus18.inc"
        
        Declare LCD_DTPin = PORTB.4
        Declare LCD_RSPin = PORTB.2
        Declare LCD_ENPin = PORTB.3
        Declare LCD_Interface = 4
        Declare LCD_Lines = 2
        Declare LCD_Type = Alphanumeric
           
        Dim Text As String * 15
        Dim Character As Byte
        Dim Index As Byte
    
        Text = "Hello World"
        For Index = 0 To Len(Text) - 1
            Character = Text[Index]
            Print At  1 ,  1 , Dec Character, " "
            Print At  2 , Index + 1, Character
            DelayMS   100  
        Next
    The above program will re-create the string on line 2 of the LCD, and display each character's decimal value on line 1. Remember, a string is, essentially, a byte array but with a null terminator.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Member Frizie's Avatar
    Join Date
    Apr 2003
    Posts
    174
    Thumbs Up
    Received: 2
    Given: 1
    Total Downloaded
    741.23 MB

    0 Not allowed!

    Default Re: How convert ASCII to char?

    Thanks Les,

    Your answer is the solution, indeed no ASC instruction necessary.
    I'm sleepy ánd stupid today, because I could think of that solution too.
    But in all my craziness, I was completely forgotten to look or even think on arrays.

    I will use this in my application to display alphabetic characters on 7-segment LED displays -as far it is possible- but most of the alphabet characters will, only "k", "m", "v", "w", and "x" are hard to do.


    @ JohnGB.
    Indeed it is not possible what I wrote in my example (the result was also '0' (zero)).
    With MID$ I filter out the characters one by one, after that it should be converted from one string character to a BYTE.
    Thats why I asked for an instruction as ASC, which would do the job, but the solution that Les has given, is also a working solution.



    ** Speaking about sleepy, I have the title wrong, it should be "How to convert ASCII to BYTE" or something...
    Maybe someone can improve that?
    Last edited by Frizie; 5th September 2017 at 21:19.
    Ohm sweet Ohm: www.picbasic.nl

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Prolific Poster johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,167
    Thumbs Up
    Received: 96
    Given: 1
    Total Downloaded
    2.90 GB

    0 Not allowed!

    Default Re: How convert ASCII to char?

    It is also the solution I gave you
    JohnB

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Member Frizie's Avatar
    Join Date
    Apr 2003
    Posts
    174
    Thumbs Up
    Received: 2
    Given: 1
    Total Downloaded
    741.23 MB

    0 Not allowed!

    Thumbs up Re: How convert ASCII to char?

    My apologies John.

    Even your solution I've completely overlooked.
    I don't know what I had yesterday.
    Was I blind? Drunk without a drop alcohol? I don't know.

    But many thanks for your quick response and solution too John!

    Frizie.
    Ohm sweet Ohm: www.picbasic.nl

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. [SOLVED !] how do i translate ascii data to char ???? using the rsin comand?????
      By JODY in forum Projects discussion
      Replies: 5
      Last Post: 6th May 2011, 08:21
    2. LCD Char Generator plugin
      By hassawfaa in forum Proton Plus Compiler v3
      Replies: 5
      Last Post: 18th September 2008, 13:49
    3. Convert variables to ASCII
      By rcurl in forum Proton Plus Compiler v3
      Replies: 4
      Last Post: 5th October 2007, 17:36
    4. [SOLVED !] LCD Char
      By Tasos Stratis in forum Proton Plus Compiler v3
      Replies: 2
      Last Post: 3rd March 2006, 21:25
    5. easier way to print LCD char
      By C_Moore in forum Wish List / Product Feedback
      Replies: 0
      Last Post: 2nd April 2005, 00:55

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts