voly
1
I'm trying to create a binary representation of a string of characters but could only print them using serial.print(arr,BIN);
Is there a way to save the binary values of each char of the string to an array or a long number?
I used this code trying to create an array but couldn't make it work:
void loop() {
String Message = "Hello World";
int l = Message.length();
int BinMessage[l];
for (int j=0; Message[j] != NULL; j++){
BinMessage[j] = String(Message[j], BIN);
Serial.println(BinMessage);
}
system
2
There are only binary values held in the computer.
What is it you're trying to do?
I think there's a stringAt or charAt or something (I don't use String) that may be worth a look for you.
jurs
3
voly:
Is there a way to save the binary values of each char of the string to an array or a long number?
Use this to store your message in a char array:
char Message[] = "Hello World";
Message[0] is then 'H'
Message[1] is then 'e'
Message[2] is then 'l'
and so on.
This might help you see it:
void setup() {
Serial.begin(9600);
char message[] = "Hello World";
int i = 0;
while (message[i]) {
Serial.print(message[i]);
Serial.print(" = ");
Serial.println(message[i++], BIN);;
}
}
void loop() {
}