Developer community
0 votes
42 views
asked by Guru (24.6k points) 29 51 78 | 42 views

1 Answer

0 votes
Left shifting of an unsigned integer is equivalent to multiplying an unsigned int by 2.

Eg1: 14<<1;

Consider a number 14-----00001110 (8+4+2)is its binary equivalent

left shift it by 1--------------00011100(16+8+4) which is 28.

Eg2: 1<<1;

consider the number as 1---00000001(0+0+1).

left shift that by 1------------00000010(0+2+0) which is 2.

left shift by 1 bit of a number=2*number

left shift by 1 bit of 2*number=2*2*number

left shift by n bits of number=(2^n)*number

Program: Program to illustrate left shift and right shift operations.

#include<stdio.h>

int main(void)

{

int x=10,y=10;

printf("left shift of 10 is %d \n",x<<1);

printf("right shift of 10 is %d \n",y>>1);

return 0;

}

Output:

left shift of 10 is 20

right shift of 10 is 5

Explanation:

Left shift (by 1 position) multiplies a number by two. Right shift divides a number by 2.
answered by Guru (39.1k points) 10 22 34

Related questions

0 votes
1 answer
asked by keem Expert (13.2k points) 27 40 59 | 98 views
0 votes
1 answer
asked by keem Expert (13.2k points) 27 40 59 | 933 views
0 votes
2 answers
asked by taye Sr Member (5k points) 7 9 12 | 33 views
+1 vote
1 answer
asked by pax Sr Member (3.2k points) 6 13 27 | 3.8k views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users