¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: String


 

INTEGER byte1;
byte1 = 42;
makestring(TX, "\\x%02X", byte1); // this sends 4 characters to TX, a literal backslash, literal x, a 2, and an A
makestring(TX, "%c", byte1); // this sends 1 character to TX with the value 42 or \x2A

Compiles and runs != working as intended

Debugger will happily show you the literal string "\x2A" even though it's not what you were intending to send.? Switch to all hex mode and you'll see \x5C\x78\x32\x41.? Mixed mode can really screw you up, especially when you're looking for what you expect to see.


On Thu, Jan 3, 2019 at 5:14 PM Kol Johnson kol.mstc@... [Crestron] <Crestron@...> wrote:
?

Hi Jeremy,

The entire thing is integers until the makestring.

I compiled and ran it before taking another guess in public ... ?

On Jan 3, 2019 1:46 PM, "Jeremy Weatherford jweather@... [Crestron]" <Crestron@...> wrote:
?

You're mixing levels... hex escapes like \xFF are interpreted by the compiler.? You're sending literal strings with 4 characters per byte: backslash, x, high nibble, low nibble.? Should be:

makestring(Output$,¡±ABC\x00\x00\x%c%c%c%c\r",byte4, byte3, byte2, byte1);

%c prints a single byte (or Character) with the specified value.? It is the dynamic equivalent to using the static \x00 escape.

On Thu, Jan 3, 2019 at 2:51 PM Kol Johnson kol.mstc@... [Crestron] <Crestron@...> wrote:
?

I had to try it to find out . . . Too easy.? Of course it didn¡¯t work . . .

Since you have converted the input to a long_integer, you already have the 4 bytes. ??

long_integer ? li_number;

integer ? byte1, byte2, byte3, byte4; ? ??
??
? ? byte1 = li_number & 255; ?// extract the lowest byte
? ? byte2 = (li_number}}8) & 255; //shift the number to the right by 8 bits (1 byte) and extract the next lowest byte
? ? byte3 = (li_number}}16) & 255; //etc.
? ? byte4 = (li_number}}24) & 255; //etc.
??
? ? makestring(Output$,¡±ABC\\x00\\x00\\x%02X\\x%02X\\x%02X\\x%02X\r",byte4, byte3, byte2, byte1);
?


Join [email protected] to automatically receive all group messages.