binary to text char.

Hello to the community

here is my code

char msg[]="hello";
char binary[512];
char* charbin[64];
char temp[]="00000000";

void setup() {
  Serial.begin(9600);         // open serial port at 9600 baud
}

void loop() {
  for(int i=0; i<5; i++){
    byte c = msg[i];   // read one character
    for(int i=0; i<8; i++) {  
      if ((c%2)==0){
        binary[i]='0';      // print the least significant bit
        c /= 2;
      } 
      else if((c%2)==1){      // move to next significant bit
        binary[i]='1';
        c /= 2;  
      }
    }
  }
  for (int i=0; i<64; i++){
   for (int a=0; a<8; a++){
    temp[a]=binary[a];
   }
  charbin[i] = temp; 
  }
  Serial.println(charbin);
  delay(2000);
}

all i want to do i break the sting of 64 chars to binary ( so 8*64=512 right?????? 0 and 1 );

and then reconstract the original sting again.

msg="hello" value in my code is for test only.

i don't understand what is wrong actualy with my code.
i get this conpilation error but i don't understand why.

any help?

all i want to do i break the sting of 64 chars to binary

Why? There must be some reason to use such inefficient representation.

i get this conpilation error

You don't tell us what error. We don't tell you want the solution is.

I suspect that it has something to do with the array of pointers.

    for(int i=0; i<8; i++) {

Are you sure you don't need a long to count to 8?

I don't know what you want to do.

A string is readable text. So the digits of "010101010" are ascii characters, not numbers.
The hexadecimal value of zero = 0x30, and one = 0x31.
So when the string "010101010" is received, the received values are : 0x30, 0x31, 0x30, 0x31, 0x30, 0x31, 0x30, 0x31, 0x30

A binary value is in my opinion just a variable with a certain value. For example: int i = 170;
The binary value of 170 = 010101010

I don't know what you want to do.

Homework?

We used to have to do these sorts of exercises in CS year 1 (early on) to make use realise that data has the meaning you attach to it. Ultimately its all just bits. That was many years ago!

well everything is for educational reason only.

i would like to brake a string of characters to zeros and ones and then reconstract from the zeros and ones the initial string.

my first thought is to brake every character to it's ASCII code binary by using one FOR LOOP

for(int i=0; i<5; i++){
    byte c = msg[i];   // read one character
    for(int i=0; i<8; i++) {  
      if ((c%2)==0){        //if it is 0,
        binary[i]='0';      // right it to the binary[i]
        c /= 2;                  // move to next significant bit
      } 
      else if((c%2)==1){     // if it is 1,
        binary[i]='1';           //right it to binary[i]
        c /= 2;                     // move to next significant bit
      }
    }
  }

and until this point everything works great.
if i try a Serial.print(binary) i get a sting of 40 zeros and ones

my problem starts when i try to break every 8 bits to an Array of strings. ( i am thinking that it would be nice to have them organised in on string( for example "01010101","10101010")

and my problem startson the reconstruction. i have this loop

for (int i=0; i<64; i++){         
   for (int a=0; a<8; a++){
    temp[a]=binary[a];   // put every bit in order inside temp
   }
  charbin[i] = temp; / write temp in to charbin[i]
  }

but i get this compilation error : call of overloaded 'println(char*[64])' is ambiguous.

am i thinking correct ?

wouldn't this be the way to do it ?

if not what could i do to break 64 characters in to zeros and ones and how can i reconstruct from zeros and ones the same sting of 64 chars ?

i get this compilation error : call of overloaded 'println(char*[64])' is ambiguous.

can any one tell me why i get this compilation error?

can any one tell me why i get this compilation error?

No.

and my problem startson the reconstruction. i have this loop

for (int i=0; i<64; i++){         
   for (int a=0; a<8; a++){
    temp[a]=binary[a];   // put every bit in order inside temp
   }
  charbin[i] = temp; / write temp in to charbin[i]
  }

but i get this compilation error : call of overloaded 'println(char*[64])' is ambiguous.
Where is there a call to println() in that snippet?

i have it outside of the loop.

i want to print out everything after it is done.

you have something else in your mind ?

void loop() {
  for(int i=0; i<5; i++){
    byte c = msg[i];   // read one character
    for(int i=0; i<8; i++) {  
      if ((c%2)==0){
        binary[i]='0';      // print the least significant bit
        c /= 2;
      } 
      else if((c%2)==1){      // move to next significant bit
        binary[i]='1';
        c /= 2;  
      }
    }
  }
  for (int i=0; i<64; i++){
   for (int a=0; a<8; a++){
    temp[a]=binary[a];
   }
  charbin[i] = temp; 
  }
  Serial.println(charbin);
  delay(2000);
}

char msg[]="hello";
char binary[512];
char* charbin[64];
char temp[]="00000000";

void setup() {
Serial.begin(9600); // open serial port at 9600 baud
}

and those are the declarations and setup

char* charbin[64];

So, charbin is an array of pointers (to strings).

  Serial.println(charbin);

The println() method does not have an overload that can print an array of strings. You could print the ith element of the array (in a for loop, if needed).