1

I am trying xil_printf() inside a for loop and feeding it to a SendBuffer over uart. How can print the characters instead of integers ? All it is printing is hex number...

uint32_t IRAM;
for(Index=0; Index<tsize; Index++){
  int sb = Index*sizeof(uint32_t);
  IRAM = XIo_In32(RAMADD+sb);
  xil_printf("Data: %08x\n\r",IRAM);
}

This prints hex charaters:

Data: 00004241
Data: 00004443
Data: 00004645
Data: 00004847

I tried :

xil_printf("Data: %08c\n\r",IRAM)

and it prints single characters :

Data: A
Data: C

How can I print the the following (converting hex charaters 4241 to AB, 4443 to CD etc...) ?

Data: AB
Data: CD
chickegg
  • 105
  • 1
  • 2
  • 9

1 Answers1

3

You need to print two bytes/characters, so you can specify it explicitly in the format string:

xil_printf("Data: %c%c\n\r", char1, char2);

But first you need to calculate the bytes to print. For example:

int char1 = (IRAM >> 8) & 0xff;
int char2 = IRAM & 0xff;

(possibly switch char1 <-> char2; I am not sure about what order you want to print them in)

anatolyg
  • 26,506
  • 9
  • 60
  • 134
  • genius. that works... Can you explain the `IRAM >> 8` ? This shifts by 1-byte getting the next char, correct ? – chickegg Nov 13 '13 at 21:11
  • @chickegg Yes; but you should be careful to avoid confusion about what is "next" char. Your definition of "next" is the little-endian one. According to big-endian ordering, the other byte (`xxx >> 0`) is the "next" one. Names like "more significant" and "less significant" are not ambiguous in this way. – anatolyg Nov 13 '13 at 21:17