View Single Post
Old 01-10-2018, 06:19 AM   #39
fundorin
Banned
 
Join Date: Feb 2014
Location: Moscow, Russia
Posts: 554
Default

Quote:
Originally Posted by goldenarpharazon View Post
To manipulate characters for SYSEX one needs to understand 7 bit ASCII characters and the difference between printable and non printable characters. There is a lot of tutorial material on the nature of characters for the C programming language but take care in that C strings are rather different to EEL strings.
Thank you for trying to help. This is what I don't get.

Let's take a simple example (variable position has int 11 value):
Code:
    num1 = sprintf(#,"\\x%02X", position);
    num2 = sprintf(#, "%s", num1);
    num3 = "\x0B";

    printf("position - %d\n", position);
    printf("num1 - %s\n", num1);
    printf("num2 - %s\n", num2);
    printf("num3 - %s\n", num3);
    printf("cnv3 - %s\n", hex2str(num3));
output:


We have dec int position with value 11. Printed as double.
We write position into num1 in hex format as a string, adding "\x" in front and making it two characters, minimum. Printed as a string.
We write num1 into num2 in string format as a string. Printed as a string.
We assign "\x0B" text string as a value to num3. Cannot be printed as a string. Why?!
If we convert it into string with a function, then it can be printed as a string.
How come that direct assignment makes that "\x0B" string a hex value for oscii-bot?

P.S. Conversion function:
Code:
function hex2str(str_in) local(str_out, pos, len) (            // Formatting HEX values to strings 
    strcpy(str_out=#,""); 
    len=strlen(str_in);
    pos=0;
    while (pos<len) (
        strcat(str_out,sprintf(#,"%02X ",str_getchar(str_in,pos)));
        pos+=1;
        );
      str_setlen(str_out,strlen(str_out)-1); // returns str_out
    );
fundorin is offline   Reply With Quote