Thread: Best way to convert ascii UART characters??

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    89

    Best way to convert ascii UART characters??

    Hello...
    I have a UART and am sending 4 characters + return character....Example:

    '32', '34', '41', '33', '0d' (24A3 + return)...the 2 is a command and will be used in a switch statement. I would somehow?? strip 2 and convert 4A3 to an integer....I am not sure how or even if I should use atoi for this....
    Any help would be appreciated...

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,156
    Well if you have all the characters in a buffer, like

    char buff[] = "24A3\r";

    Then strtol, strtoll - cppreference.com
    long x = strtol(&buff[1], NULL, 16);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Outputting ASCII characters?
    By Jamsan in forum C++ Programming
    Replies: 3
    Last Post: 03-24-2003, 07:14 PM
  2. ASCII Characters
    By GreenCherry in forum Game Programming
    Replies: 6
    Last Post: 10-13-2002, 01:51 AM
  3. All the ASCII characters
    By Shadow12345 in forum C++ Programming
    Replies: 5
    Last Post: 05-20-2002, 01:20 PM
  4. ascii characters
    By Denethor2000 in forum C++ Programming
    Replies: 3
    Last Post: 03-20-2002, 05:26 AM
  5. ASCII characters
    By NuKid in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2001, 09:14 PM

Tags for this Thread