Go Down

Topic: Question about String (Read 420 times) previous topic - next topic


It may be polite to call strangers 'sir' in your culture, but in my culture it's not appropriate - please stop it.

It sounds as if you want to compose a message which consists of a combination of ascii and binary data. In general that's not the sort of thing that you would usually hard-code (instead, you would compose the message from data) but you can define it using initialised data if that's what you want to do.

Code: [Select]

char message[] = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0xFF, 0xFA, 0xFB, 0xFD};

Note that this is a character array but it isn't an ascii string (there are non-printable characters in it and it is not terminated) so many of the functions available to deal with normal ascii strings wouldn't work. But if you have a particular need to construct a hard-coded message combining ascii and hex characters, that's one way to do it.
I only provide help via the forum - please do not contact me for private consultancy.


Fpr modular checksum.

You use unsigned 8-bit ints (bytes) and just add the value of each new byte to the last. Don't worry about overflow. The modular checksum is that final byte inverted and add 1 (2's complement). With that anyone can check the data.

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Go Up