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




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.