Fabiman89
Fabiman89

Reputation: 33

how to know if 2 bits can make xor java

i have a 8 bit long value ( 1 byte ) called dividendo (with the value 0x98 = 10011000), i want to make a xor ( ^ ) between the 3 first bits from dividendo (100 ) and the value of variable div (0x5 = 101) so i can have this ( 001 ), the if sentence its trying to know if t and div have the same size in bits so they can make a xor, It is for a crc code in java

i want to do this:

    long t, res;
    long dividendo = 0x98;   
    long div = 0x5;
    for(int i=0; i< 8;i++ ){       // to extract bit by bit from a byte
     t=(dividendo   >>> (7-i));      
    if( div ^ t ) {
        res = t^div;
        System.out.println(Long.toHexString(res));
    }

Upvotes: 0

Views: 72

Answers (1)

Epiglottal Axolotl
Epiglottal Axolotl

Reputation: 1048

I think you could probably just say if(div^t!=0), if I understand correctly what you are saying.

Upvotes: 2

Related Questions