Hot!Converting from ASCII to gray code?

Author
Jack_Daxter
New Member
  • Total Posts : 2
  • Reward points : 0
  • Status: offline
2018/05/16 04:44:41 (permalink)
0

Converting from ASCII to gray code?

Hello!
 
I'm currently in the middle of writing code involving conversions between an ASCII character and its gray code equivalent. I've attached a file for the test code I'm using. I'm stuck trying to figure out how exactly to tell the code to go about converting it as I have spent hours trying to see what to put between the call ascii and call gray so everything flows as it's supposed to. I was wondering if you guys can help or at least give your thoughts. Any help is appreciated!
#1

10 Replies Related Threads

    pcbbc
    Super Member
    • Total Posts : 454
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/16 10:05:13 (permalink)
    +2 (2)
    Jack_DaxterASCII character and its gray code equivalent
    There's no such thing as a "gray code equivalent" of ASCII.  Any implementation of grey code for selection of ASCII would be entirely implementation dependent.


    I'm also not sure what practical application such an encoding would have?  The purpose of grey code is for rotary encoding such that only one bit ever changes between adjacent code points.  ASCII strings rarely consist of adjacent code points...
     
    Unless you are using a rotary encoder to select an ASCII character e.g. 0-9?  In which case you want to go the other way around - from grey to ASCII.
     
    What range of ASCII characters are you working with?  All 128 or just a subset?
     
    Looks like a homework assignment to me.... wink: wink
    #2
    JorgeF
    Super Member
    • Total Posts : 3287
    • Reward points : 0
    • Joined: 2011/07/09 11:56:58
    • Location: PT/EU @ Third rock from the Sun
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/16 12:24:35 (permalink)
    +1 (1)
    Hi
    pcbbc
    Looks like a homework assignment to me.... wink: wink

    Yes. It looks like something I would ask my students to do, back in the days I was a teatcher.


     
     
    Best regards
    Jorge
     
    #3
    jack@kksound
    code tags!
    • Total Posts : 2762
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/16 12:38:37 (permalink)
    0
    JorgeF
    Hi
    pcbbc
    Looks like a homework assignment to me.... wink: wink

    Yes. It looks like something I would ask my students to do, back in the days I was a teatcher.


     
     
    Best regards
    Jorge
     


    Yes but the OP seems to have left out a reat deal of detail about the "assignment". ASCII to GRAY makes little sense unless the actual task is to convert the binary values of the standard ASCII characters to a gray code. Still a bit of a puzzle as to what would be used for.....
    #4
    JorgeF
    Super Member
    • Total Posts : 3287
    • Reward points : 0
    • Joined: 2011/07/09 11:56:58
    • Location: PT/EU @ Third rock from the Sun
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/16 12:45:08 (permalink)
    +1 (1)
    Hi
    jack@kksound
    Yes but the OP seems to have left out a reat deal of detail about the "assignment". ASCII to GRAY makes little sense unless the actual task is to convert the binary values of the standard ASCII characters to a gray code. Still a bit of a puzzle as to what would be used for.....

    Usually this kind of "aparent nonsense" is used to get people to get some understanding of the various possible meanings a simple byte can have.
    How many threads is this forum have been opened with questions that show serious lack of it?
     
     
    Best regards
    Jorge
     
    #5
    Jack_Daxter
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/16 13:05:03 (permalink)
    0
    Correct! This is part of a homework project that my class has been assigned to do to gain a better understanding of assembly code.

    It seems i have misinterpreted the question as I thought I had to convert a decimal to ascii and then to Gray code. But now that I think about it, it doesn't make sense.
    post edited by Jack_Daxter - 2018/05/16 14:47:43

    Attached Image(s)

    #6
    1and0
    Access is Denied
    • Total Posts : 8396
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/16 14:15:53 (permalink)
    0
    Logical right shift the value then xor it with the original value.
    #7
    1and0
    Access is Denied
    • Total Posts : 8396
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/18 02:45:04 (permalink)
    +2 (2)
    Now that your Post #6 has been approved by the Moderator. It looks like your homework assignment is to
    1. write assembly code to convert a decimal number to binary and output it to PORTB.
    2. write assembly code to convert an ASCII character to Gray code and output it to PORTB.
    For #1, it should be easy as a decimal number is already stored in the 16F84A as binary, so just write it to PORTB.

    For #2, I've already told you how to do the conversion in my previous post, so code it yourself and we will help you learn and debug it. However, noone here will do your homework for you.
    #8
    jack@kksound
    code tags!
    • Total Posts : 2762
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/18 09:36:40 (permalink)
    0
    ..a decimal number is already stored in the 16F84A as binary..

    This MAY be a risky assumption, there are many ways to "store" a "decimal number", lots of formats to choose from.
     
    #9
    JorgeF
    Super Member
    • Total Posts : 3287
    • Reward points : 0
    • Joined: 2011/07/09 11:56:58
    • Location: PT/EU @ Third rock from the Sun
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/18 10:09:17 (permalink)
    0
    Hi
     
    As it is in the text, the "decimal" word might mean BCD or packed BCD.
    But this is the kind of thing that can be clarified with the teatcher.
     
    Or the OP might interpret it better than us due to its classroom experience. 
     
     
    Best regards
    Jorge
     
    post edited by JorgeF - 2018/05/18 10:13:37
    #10
    1and0
    Access is Denied
    • Total Posts : 8396
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Converting from ASCII to gray code? 2018/05/18 11:09:21 (permalink)
    +1 (1)
    JorgeF
    Or the OP might interpret it better than us due to its classroom experience. 

    Yeah ... "Be sure to utilise your notes taken in class to make the appropriate conversions for your chosen numbers and characters. Use what you learned in class ..."
    #11
    Jump to:
    © 2018 APG vNext Commercial Version 4.5