3<<1 = 6 | Sololearn: Learn to code for FREE!

+24

# 3<<1 = 6

Can you please tell me what is the meaning of this?and why the answer is "6"...help me

4/25/2019 2:51:50 AM

Pewππ°

+11

x << y Returns x with the bits shifted to the left by y places (and new bits on the right-hand-side are zeros). This is the same as multiplying x by 2**y. x >> y Returns x with the bits shifted to the right by y places. This is the same as dividing xby 2**y. Here 3*2**1=3*2=6

+9

Thanks Edwin ππ

+9

Thanks Knight Wing broπ€ͺ

+8

Because '<<' this is bits operation on the memory. One position to the left. Example: Bits representation : 0011 = 3 Bits operation moving one position to the left '<<' (1) : 0110 = 6

+8

Thanks ΞΊΞ΅vΞΉΟ lΞ΅vΞΉΟ ππ

+7

Thanks Electron_03 ππ

+7

+6

This is actually a question related to bitwise operators which are mostly useful in scientific computing and stuff like that. You are using a bitwise operator called as 'left shift' (<<) in python language. So, before talking about the operation, I will put some points which will help you to understand it in a better way. Any number in this whole universe, can be represented with the help of decimals!!! Yep don't get confused here is an example!! Ex:- 3 is an individual number but it can be expressed as 3.0 or 3.000 or 3.0000000000,etc........ We don't consider them eventually because they are zeroes. But remember every number can be expressed in this manner. So, when you are using an operation like this:- '3<<1', you are actually saying to computer that 'hey, shift 3 by 1 bit to the left!! ' And, what it does is it takes 1 zero after the decimal places and append it to the decimal value of 3 which is 11.After the operation, the resultant number is 110,which is actually equal to 6

+5

ππNice question. I have this doubt

+5

Sharanka Sri ππ

+3

This can help you :) there is a bits table of memory representation : https://www3.ntu.edu.sg/home/ehchua/programming/java/datarepresentation.html

+2

(3<<0) = 0b00000011 = 3 = 0+0+0+0+0+0+2+1 (0b) this mean that number is written by binary (<<) β> this mean (shift to left) (3<<1) β> shift one bit to left (3<<1) = 0b00000110 = 6 = 0+0+0+0+0+4+2+0 example of conversion from binary to decimal : 10110100 (binary) = 128+0+32+16+0+4+0+0 = 180 (decimal number )

+1

https://www.sololearn.com/learn/4087/?ref=app

+1

coooool bro

-1

L rule error

-3

<< is the bitwise left shift operator. 3 << 1 means shifting every bit of the binary value of 3 to 1 position left. 3 = 00000111 3 << 1 = 00001110 = 6