Thread: Print to hyperterminal in Hexa (Or Decimal)

  1. #1
    Registered User
    Join Date
    Nov 2010

    Print to hyperterminal in Hexa (Or Decimal)

    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.
    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?


  2. #2
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    United Kingdom
    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:
    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
    Oregon, USA
    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...
    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:
    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, 02: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, 08:26 PM