Advertisements
Advertisements

Swapping every two bits in byte Java Solution

In the Swapping of two bits in byte in java, the output should look like something below: Swap all the pair of bits in a byte. Before swapping: 11-10-11-01 After swapping: 11-01-11-10 The code is written and tested in Netbeans. Code: import java.util.Arrays; import java.util.Scanner; public class bitbyte { public static void main (String[] args)

Advertisements
Convert decimal to binary in java

Converting Decimal to Binary in Java

The below code will convert decimal number in binary format [bits] in java. I have taken a byte as an array, i.e. 8. You can take more depending on your needs. The input for the current program is a with the value 48. You can take the input through scanner too. Code: public class bitbyte

Advertisements
%d bloggers like this: