Strings for Exchanging Data
Strings can contain characters that represent numbers. It is important to understand that a string with “1234” is very different from an int with a value of 1234 that you can add, subtract, multiply, etc. Instead, “1234” are just the characters that represent the numbers.
For example, take a string variable named s that contains the characters “1234”. The quotes make it a string. Without the quotes, n = 1234 creates an int variable that will work in calculations.
Radio and Internet devices often have to convert numbers to strings and add names before sending them to other devices. The devices that receive the string have to find the names and numbers in the string. In many cases, they also have to convert the string representation of the number back to an int or float so that it can be used in calculations. For example, here are two names and numbers:
One project would have to assemble or packetize the string into this before transmitting:
The project running in the receiver might have to parse this data. In this case, parsing would involve breaking the string into its four substrings: “First number”, “1234”, “Second number”, and “5678”. It might also be up to the receiver to find the “1234” and “5678” substrings and convert them back to int variables that the project can use for calculations.
Sending and receiving projects might also have to encrypt the string so that nobody other receivers cannot figure out what the string contains. Here is a very simple example of an encrypted string. The transmitter would have to change each character in some way, and the receiver would have to change each character back to the original before it can process the data. Can you decrypt it and figure out what it really says?