Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to extract a set of binary strings in java

// a java code that extracts a set of binary strings 6 bits at a time

import java.util.Scanner;

public class Demo {

  
    static int bitExtracted(int number, int k, int p)
    {
        return (((1 << k) - 1) & (number >> (p - 1)));
    }

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        String binary = "";
        int x, number = 114, k = 6, p = 1;
        x =  bitExtracted(number, k, p);
        while (x != 0) {
            int remainder = x % 2;
            binary = remainder + binary;
            x = x / 2;
        }
        System.out.println("The extracted number is "+"(" +x +")"+": "+ binary);


    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: clear datepicker javafx 
Java :: Java/Perl - "sprintf function in java" or "string format" 
Java :: java unused import statement 
Java :: kotlin dependency injection 
Java :: Run the ls command in the terminal to see the uncompiled .java file 
Java :: getcokor from drawable in java android studio 
Java :: a multi-value map, Map<K, Collection<V, supporting multiple values per key 
Java :: random number in java between 10 and 20 
Java :: fill a 2d array java 
Java :: pgzint install windows 10 
Java :: what isz meaning of EL in jsp 
Java :: torres de hanoi java 
Java :: get value from dynamic input android 
Java :: Java Finding Extreme Values 
Java :: concurrentskiplistset infinite loop in jdk 
Java :: springBoot Disable a Specific Auto-Configuration 
Java :: square operator java 
Java :: java pattern matching 
Java :: batch file to switch between java version 
Java :: java accept user input 
Java :: java swing place objects vertically 
Java :: contoh object dalam oop java 
Java :: java max array 
Java :: java function 
Java :: date data type in java 
Java :: find repeated elements in array java 
Java :: java compare char 
Java :: java float 
Java :: what is java steam 
Java :: java non-breajubg soace remove 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =