Bit shifting when using CC1101

Hello. I am using a CC1101 module (SPI) with the ELECHOUSE_CC1101 libary : https://github.com/tomxue/Arduino___CC1101/blob/master/ELECHOUSE_CC1101/ELECHOUSE_CC1101.h

i decided to send data using 8 bit binary with a character array to convert it down. character → decimal index → binary

i have it outputting pretty much every step of the way for troubleshooting and i get some wierd bit shifting when recieving.
so in my array “a” is at index 5, which is binary 00000101
I split this into a byte array and transmit that byte array using

ELECHOUSE_cc1101.SendData(TX_buffer,xsize);

my full code is too long and messy to put up in full, however the main bit is here:

#define xsize 8
byte TX_buffer[xsize] = {0};

void loop(){

int zeros = String(sbit,BIN).length();
  String binary;
    for (int i=0; i < 8 - zeros; i++) {
    binary = binary + "0";
  }
  binary = binary + String(sbit,BIN);
  for(int i = 0; i <= 8; i++){
    TX_buffer[i] = byte((binary.substring(i,i+1)).toInt());
  }
  ELECHOUSE_cc1101.SendData(TX_buffer,xsize);
}

pretty simple. I put the binary into a string

Hello. I am using a CC1101 module (SPI) with the ELECHOUSE_CC1101 libary : https://github.com/tomxue/Arduino___CC1101/blob/master/ELECHOUSE_CC1101/ELECHOUSE_CC1101.h

i decided to send data using 8 bit binary with a character array to convert it down. character → decimal index → binary

i have it outputting pretty much every step of the way for troubleshooting and i get some wierd bit shifting when recieving.
so in my array “a” is at index 5, which is binary 00000101
I split this into a byte array and transmit that byte array using

ELECHOUSE_cc1101.SendData(TX_buffer,xsize);

my full code is too long and messy to put up in full, however the main bit is here:

#define xsize 8
byte TX_buffer[xsize] = {0};

void loop(){
int sbin = 5 //this is a "a"
int zeros = String(sbit,BIN).length();
  String binary;
    for (int i=0; i < 8 - zeros; i++) {
    binary = binary + "0";
  }
  binary = binary + String(sbit,BIN);
  for(int i = 0; i <= 8; i++){
    TX_buffer[i] = byte((binary.substring(i,i+1)).toInt());
  }
  ELECHOUSE_cc1101.SendData(TX_buffer,xsize);
}

pretty simple. I put the binary into a string to help with formatting.
now in theory i should be able to recieve that same binary code and run it though in reverse to get bach to the number 5 and check that agains the array to rebuild the message.

The problem is im getting a different binary value back.
Examples (o=original, c=corrected)
o: 00101100 c: 00010110 ==r
o: 00010010 c: 00001001 ==e
o: 00101010 c: 00010101 ==q
o: 00110010 c: 00011001 ==u
o: 00010010 c: 00001001 ==e
o: 00101110 c: 00010111 ==s
o: 00110000 c: 00011000 ==t
o: 11111110 c: 01111111 == ETX actual: 11111111

im having to correct it by simple takeing the sybstring 0,7 and adding another 0 before it.

holder = "0" + holder.substring(0,7);

however this means my max number i can use is 127 rather that 255, i basically loose half my usable space.

has anyone else seen this issue before ? or have a better work around ?

Duplicate of http://forum.arduino.cc/index.php?topic=535706

Reported to mods

Threads merged.