Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

In similar fashion we will use (RIGHT – SHIFT) to retrieve bits from val 6 at a time

// 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);


    }
}
 
PREVIOUS NEXT
Tagged: #In #similar #fashion #retrieve #bits #val #time
ADD COMMENT
Topic
Name
4+9 =