+ 6

Need help with question asked in challange?

int num=8; System.out.print(num>>1); //Outputs 4 Can anybody explains.

27th Jan 2018, 11:47 AM
Sunil Thakali
Sunil Thakali - avatar
5 Answers
+ 15
8 bitwise is 00001000. >> means shift the bits to the right once, so the result is 00000100, which in decimal is 4
27th Jan 2018, 12:00 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 7
that's bitwise. but I think it is not in course !!!
27th Jan 2018, 11:57 AM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 5
Thanks..It was asked as the challange question
27th Jan 2018, 12:03 PM
Sunil Thakali
Sunil Thakali - avatar
+ 3
Shifting bit to right or left result to divide or multiply by two, due to the base 2 on wich binary numbers operate, as shifting a digit in decimal ( base 10 ) will result to divide or multiply by ten... So, there's no need to convert explicitly a number to binary representation to be able to get the result of a bit shifting ^^
27th Jan 2018, 12:56 PM
visph
visph - avatar
+ 1
@nikolay I have been looking for you for along time please can you help me there https://www.sololearn.com/discuss/1034923/?ref=app
29th Jan 2018, 7:05 AM
Abdurrahman Abulgasim
Abdurrahman Abulgasim - avatar