Berikut ini contoh perbedaan shift logical dan arithmetic

#include <stdio.h>
#include <conio.h>

void show_binary(char u){
  int n;

  for(n=128;n>0; n=n/2 )
    if(u & n)
        printf("1");
    else
        printf("0");

  //printf("\n");
}

main(){
    unsigned char x1 = 0xF0;
    unsigned char x2 = 0x0F;
    unsigned char x3 = 0xCC;
    unsigned char x4 = 0x55;

    printf("\nHexa Decimal");
    printf("\nx1=0x%02X \nx2=0x%02X \nx3=0x%02X \nx4=0x%02X",x1,x2,x3,x4);
    printf("\nBinary");
    printf("\nx1=");show_binary(x1);
    printf("\nx2=");show_binary(x2);
    printf("\nx3=");show_binary(x3);
    printf("\nx4=");show_binary(x4);

    printf("\n\nBinary x<<3");
    printf("\nx1=");show_binary(x1<<3);
    printf("\nx2=");show_binary(x2<<3);
    printf("\nx3=");show_binary(x3<<3);
    printf("\nx4=");show_binary(x4<<4);
    printf("\nHexa Decimal x<<3");
    printf("\nx1=0x%02x \nx2=0x%02X \nx3=0x%02X \nx4=0x%02X",(unsigned char)(x1<<3),(unsigned char)(x2<<3),(unsigned char)(x3<<3),(unsigned char)(x4<<3));

    printf("\n\nBinary x>>2 (Logical)");
    printf("\nx1=");show_binary(x1>>2);
    printf("\nx2=");show_binary(x2>>2);
    printf("\nx3=");show_binary(x3>>2);
    printf("\nx4=");show_binary(x4>>2);
    printf("\nHexa Decimal x>>2 (Logical)");
    printf("\nx1=0x%02X \nx2=0x%02X \nx3=0x%02X \nx4=0x%02X",x1>>2,x2>>2,x3>>2,x4>>2);

    printf("\n\nBinary x>>2 (Arithmetic)");
    printf("\nx1=");show_binary((signed char)x1>>2);
    printf("\nx2=");show_binary((signed char)x2>>2);
    printf("\nx3=");show_binary((signed char)x3>>2);
    printf("\nx4=");show_binary((signed char)x4>>2);
    printf("\nHexa Decimal x>>2 (Arithmetic)");
    printf("\nx1=0x%02X \nx2=0x%02X \nx3=0x%02X \nx4=0x%02X",(unsigned char)((signed char)x1>>2),(unsigned char)((signed char)x2>>2),(unsigned char)((signed char)x3>>2),(unsigned char)((signed char)x4>>2));

    printf("\n");
}