Why does this return 10010 instead of 00001?
0110 >> 2 // 10010
I thought the bits would be shifted to the right 2 times, but they’re not. The output I expected was 0001 or 1 but I got 0 instead. Why is this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
0110 is an octal constant because it starts with a zero:
This is Python, but the same is true of many other languages with octal constants (Java, C, JavaScript, …). Not all languages provide binary constants. If you don’t have them, you can use hexadecimal constants instead (0b0110 is 0x6, for example).