Hi,

This code shif left on array bitwse, but dŽont work whel.

Same body say me whre is the probem?

0000000 0000000 11111111
after 10 shifts

00000011 11111100 00000000



Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void imprime(unsigned char texto);
void shift_right(unsigned char *ar, int size, int shift, unsigned char valent);
void shift_4bits_left(unsigned char* array, int size,int shift);
int main()
{
unsigned char alfabeto[8] ={0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000010, 0b00000000, 0b0000001};
int a,b;
unsigned char Shift_data=1;
shift_right(&alfabeto[0], 8, 2,1);


  //imprime array
for (a=0; a<8; a++)
{
  imprime(alfabeto[a]);
}
  return 0;
}

void shift_right(unsigned char *ar, int size, int shift, unsigned char valent)
{
   unsigned short carry = 0;
    while (shift--) {
        for (int k = size-1 ; k >= 0; --k) {
            unsigned short next = (ar[k]<<1) & 0x80;
            ar[k] =  (ar[k] << 1) | carry ;

            carry = next;
        }
    }
}

void imprime(unsigned char texto)
{
  int i;
  for (i = 0; i < 8; i++) {
      printf("%d", !!((texto << i) & 0x80));
  }
  printf("\n");
}