IAR C, 32bit integer to string?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how to convert an 32bit integer to string in IAR C?

AVRGCC using the ltoa, IAR C what is using?

Learn as long as you live

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
unsigned long yourVariable;

typedef union{
    struct{
        unsigned char a;
        unsigned char b;
        unsigned char c;
        unsigned char d;
    }byte;
    unsigned long dword;
}TYPE_DWORD_TO_BYTES;

TYPE_DWORD_TO_BYTES newVariable;

newVariable.dword = yourVariable;

if (let's say):

yourVariable = 0xDDCCBBAA

then:

newVariable.byte.a = 0xAA
newVariable.byte.b = 0xBB
newVariable.byte.c = 0xCC
newVariable.byte.d = 0xDD

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

if (let's say):

yourVariable = 0xDDCCBBAA

[...]


That would be decimal 3721182122 (if unsigned) or -573785172 (if signed). Dont you think that kzdev wants one of the strings "3721182122" or "-573785172"?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ooooops,

Johan you are right. It was a hasty repply.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer