Print to hyperterminal in Hexa (Or Decimal)

This is a discussion on Print to hyperterminal in Hexa (Or Decimal) within the C Programming forums, part of the General Programming Boards category; Hi, I'm programming an Evaluation Kit and I'm tryin' to print the acquired data by an A/D converter to Hyperterminal, ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Print to hyperterminal in Hexa (Or Decimal)

    Hi,
    I'm programming an Evaluation Kit and I'm tryin' to print the acquired data by an A/D converter to Hyperterminal, but it's been printed in ASCII.
    Example:
    I have this values stored in the SRAM:
    It's an array (TxBuffer) with 8 bits per position.
    TxBuffer [0] = 64
    TxBuffer [1] = 10
    How do I print exactly this values to hypeterminal?

    Thanks!

  2. #2
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    I'm not 100% sure what you mean about the hyperterminal stuff, but in C, if you want to display numbers in hexadecimal format you can do it using either the %x or %X specifier in printf:
    Code:
    printf("%X", num);
    So if you had a string then you would have to loop through it character by character and print each character out separately in Hex.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    If I understand you right, you're just trying to combine the two 8-bit values into a single integer that you can print, right? I'm also assuming that TxBuffer[1] has the more significant bits than TxBuffer[0]? If not, just swap the 0 and 1 indexes...
    Code:
    int val = TxBuffer[0] | (TxBuffer[1] << 8);
    printf("%X", val);
    Of course, since 8-bit values are printed neatly in hex you could simply print them without merging them like so:
    Code:
    printf("%X%X", TxBuffer[1], TxBuffer[0]);
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal place range. simple help needed
    By Chris0724 in forum C Programming
    Replies: 8
    Last Post: 09-10-2008, 02:41 AM
  2. Replies: 3
    Last Post: 07-04-2008, 12:39 PM
  3. hex to binary,hex to decimal
    By groovy in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 01:14 AM
  4. Binary traslator
    By NiVaG in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2005, 07:01 PM
  5. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 07:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21