Home » Code Snippets » C/C++ Code Snippets

C program to shift entered data four bits to the left.

By: IncludeHelp, On 04 NOV 2016

In this c program we will learn how we can shift four bits of entered data to the left using left shift operator in c programming language?

Here, we are reading an integer number and shifting four bits of the number to the left; data before and after shifting is printing in both format decimal and hexadecimal.

C program - four bits shifting to left of entered data

Let’s consider the following program

/*C program to shift entered data four bits to the left*/

#include <stdio.h>

int main()
{
	int data;
	
	printf("Enter value of data: ");
	scanf("%d",&data);
	
	printf("Entered value is %d (decimal), %x (hex)\n",data,data);
	
	/*shifting 4 bites left*/
	data=data<<4;
	printf("After shifting value is %d (decimal), %x (hex)\n",data,data);
	
	return 0;
}

Output

    Entered value is 512 (decimal), 200 (hex) 
    After shifting value is 8192 (decimal), 2000 (hex)

COMMENTS




Copyright © 2024 www.includehelp.com. All rights reserved.