CodeGym /Courses /Java Multithreading /Practice using logical operators

Practice using logical operators

Java Multithreading
Level 10 , Lesson 6
Available

"Hi, Amigo!"

18
Task
Java Multithreading, level 10, lesson 6
Locked
Fork/Join
1. Create a BinaryRepresentationTask class. To do this, click Alt+Enter -> Create Class... on the red class name in IntelliJ IDEA. (The class must inherit RecursiveTask). The constructor's parameter is int x. 2. Implement the compute method: the number should be converted to binary.
9
Task
Java Multithreading, level 10, lesson 6
Locked
Such tricky exceptions!
Fix the implementation of the checkAFlag method so that it never throws exceptions. Preserve the screen output logic. The main method is not tested.
18
Task
Java Multithreading, level 10, lesson 6
Locked
Bit operations
You must implement a public int resetLowerBits(int number) method. It should clear all the bits in the number argument, except the highest bit set to one, and then return this number. An int is 4 bytes = 32 bits.
Comments (2)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
fzw Level 41, West University Place, United States
25 May 2020
One idea for "bit operations", take a random example i = "0..0100101": Step1: right shift i by 1 -> "0..0010010" Step2 : bitwise OR -> "0..0110111" and take this as new i Step3: repeat Step 1 and 2 until all bits after highest "1" bit are all "1", i.e., i should be "0..0111111" Step4 : right shift i by 1 -> "0..0011111" and flip all bits (I'll call this j) Now we have i: 0..0111111 j: 1..1100000 It should be clear by now how to get the highest "1" bit. reference: https://habr.com/ru/post/93172/
BlueJavaBanana Level 37
2 December 2020
Is this allowed? How do you repeat without a loop or without exceeding the size of the number? My single line solution below works but it fails verification because I am using things I am not allowed apparently.

        return Integer.valueOf(1 << (Integer.toBinaryString(number).length() - 1));