¿ªÔÆÌåÓý

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

Re: String


 

Hi Jeremy;

Your point is quite valid, and the OP may want to consider it as it relates to what he is trying to accomplish.

The OP described sending ascii text that depicted the hex characters. ?Don¡¯t know why, but that was what he showed, and it could very well actually be not what he really wants to do. ?

I read the question as asking how to get the data from the input of his module into the makestring. ?I answered that question, not whether what he asked how to do made sense. ?Who knows, maybe the string he was trying to generate eventually gets parsed by looking for ¡°\x¡±, can¡¯t read minds.

The real meat of my post was how to extract individual bytes from a long integer so he could do whatever he wants with them. ?Again, if he wanted to just send the hex bytes representing the value he should have been able to just use something like %04lX as a specifier and drop the long integer right into makestring.


From: <Crestron@...> on behalf of "Jeremy Weatherford jweather@... [Crestron]" <Crestron@...>
Reply-To: <Crestron@...>
Date: Thursday, January 3, 2019 at 8:47 PM
To: <Crestron@...>
Subject: Re: [Crestron] 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 [email protected] [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.