Beispiel #1
0
int main(void){

	unsigned int numberSix = 6; // 110
	unsigned int numberSeven = 7; // 111

	char *pConvertedNumber;
	pConvertedNumber = malloc(33 * sizeof(char));

	// ### The fourth bitwise operator we are going to work with is Shift Operator - << or >>
	// It basicly allow us to shift bits to the left or to the right. We are going to shift
	// bits first to the left.
	unsigned int shiftLeftTwo = numberSix << 2;
	printf("%s << 2 = ", convertBase(numberSix, 2, pConvertedNumber));
	printf("%s = %d\n\n", convertBase(shiftLeftTwo, 2, pConvertedNumber), shiftLeftTwo);
	// 110 << 2 = 11000 = 24

	unsigned int shiftRightTwo = numberSix >> 2;
	printf("%s >> 2 = ", convertBase(numberSix, 2, pConvertedNumber));
	printf("%s = %d\n\n", convertBase(shiftRightTwo, 2, pConvertedNumber), shiftRightTwo);
	// 110 >> 2 = 1 = 1

	free(pConvertedNumber);
	return 0;
}
main()
{
	convertBase(25);//calling the above function
}