how to find complement of a number in java
Java
// Java program to find 1's complement of n.
class GFG {
static int onesComplement(int n)
{
// Find number of bits in the
// given integer
int number_of_bits =
(int)(Math.floor(Math.log(n) /
Math.log(2))) + 1;
// XOR the given integer with poe(2,
// number_of_bits-1 and print the result
return ((1 << number_of_bits) - 1) ^ n;
}
// Driver code
public static void main(String[] args)
{
int n = 22;
System.out.print(onesComplement(n));
}
}
// This code is contributed by Anant Agarwal.
Also in Java:
- Title
- set java
- Category
- Java
- Title
- how to add multiple filter condition in Java stream filter chain
- Category
- Java
- Title
- how to print hello world in java
- Category
- Java
- Title
- spigot run command as console
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- java function for power
- Category
- Java
- Title
- java random integer
- Category
- Java
- Title
- java getter
- Category
- Java
- Title
- java loop through array
- Category
- Java
- Title
- android round double to 2 decimal
- Category
- Java
- Title
- how do i print text in java
- Category
- Java
- Title
- add element to stack java
- Category
- Java
- Title
- sign flutter app android studio
- Category
- Java
- Title
- how to split a string in java
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- java get environment variables
- Category
- Java
- Title
- catch array out of bounds exception java
- Category
- Java
- Title
- java read each lines in file
- Category
- Java
- Title
- jq selector body
- Category
- Java
- Title
- java projects
- Category
- Java
- Title
- how to use lambda in java
- Category
- Java
- Title
- StringBuilder java pop back
- Category
- Java
- Title
- java split array into two
- Category
- Java
- Title
- applicationcontext.xml
- Category
- Java
- Title
- import java.util.hashset
- Category
- Java
- Title
- regex get string between quotes java
- Category
- Java
- Title
- how to loop trough an object java script
- Category
- Java
- Title
- how to substring in java
- Category
- Java
- Title
- reverse linked list in java to get both head and tail
- Category
- Java
- Title
- snackbar not showing with bottom nav
- Category
- Java
- Title
- do while loop java
- Category
- Java
- Title
- diagonal difference hackerrank solution in java 8 using list
- Category
- Java
- Title
- java hash password
- Category
- Java
- Title
- java get first char
- Category
- Java
- Title
- how to compare strings java
- Category
- Java
- Title
- java how to make a string lowercase
- Category
- Java
- Title
- how to make a fixed size array in java
- Category
- Java
- Title
- creating array java
- Category
- Java
- Title
- get cursor position in textarea java
- Category
- Java
- Title
- how to use the this keyword in java
- Category
- Java
- Title
- how to delete an element from an array in java
- Category
- Java
- Title
- change brightness of image in java
- Category
- Java
- Title
- Java app development
- Category
- Java
- Title
- phoneword converter
- Category
- Java
- Title
- java sort method
- Category
- Java
- Title
- java 8 map foreach
- Category
- Java
- Title
- java calendar add minutes
- Category
- Java
- Title
- java null pointer exception
- Category
- Java
- Title
- switch en java
- Category
- Java
- Title
- java log base 2
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- how to create an action listener in java
- Category
- Java
- Title
- java save string in text file
- Category
- Java
- Title
- run java classpath command line
- Category
- Java
- Title
- jtable get get row
- Category
- Java
- Title
- double to string java
- Category
- Java
- Title
- convert date to calendar java
- Category
- Java
- Title
- read integer input java
- Category
- Java
- Title
- read from elasticsearch in spark
- Category
- Java
- Title
- remove item from arraylist in java
- Category
- Java
- Title
- priority queue in java
- Category
- Java
- Title
- file to image javafx
- Category
- Java
- Title
- how to make a copy of an array java
- Category
- Java
- Title
- how to reverse a string in java
- Category
- Java
- Title
- get sha key android
- Category
- Java
- Title
- how to create an abstract method in java
- Category
- Java
- Title
- java nextpermutation
- Category
- Java
- Title
- random code
- Category
- Java
- Title
- how to remove duplicates from an array java
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- getordefault java
- Category
- Java
- Title
- imagesbutton how to set background
- Category
- Java
- Title
- json request body not getting parsed by spring boot controller
- Category
- Java
- Title
- java map example
- Category
- Java
- Title
- elasticsearch api code call using highlevelrestclient
- Category
- Java
- Title
- Java array hashcode
- Category
- Java
- Title
- java linked list functions
- Category
- Java
- Title
- bukkit scheduled task
- Category
- Java
- Title
- java clone method
- Category
- Java
- Title
- sdkmanager JAVA_HOME invalid directory
- Category
- Java
- Title
- java logical operator
- Category
- Java
- Title
- java convert String to int
- Category
- Java
- Title
- enum in java
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- java stream find specific element
- Category
- Java
- Title
- Write a JAVA method that expands a given binomial (ax + by)n, where integers a, b, n are user inputs. For example, if a = 2, b = -12, n = 4 are entered the method should print or return
- Category
- Java
- Title
- file with line numbers inserted java
- Category
- Java
- Title
- do statement java
- Category
- Java
- Title
- java 8 iterating and manipulating list
- Category
- Java
- Title
- how to create a list in java
- Category
- Java
- Title
- how to return the lower of two values in one line java
- Category
- Java
- Title
- java d'intervalle de resultat
- Category
- Java
- Title
- java android development get element by id
- Category
- Java
- Title
- java rest client response json
- Category
- Java
- Title
- java fx display simple rectangle
- Category
- Java
- Title
- write an object java in a file
- Category
- Java
- Title
- java 8 loop in map
- Category
- Java
- Title
- recursive function for fibonacci series in java javascript
- Category
- Java
- Title
- initialize scanner java
- Category
- Java