java - matching different sized strings -


actually went through research docuements , got situation match binary string binary string size uknown ex:

"1110000010001001101011010100010000101101001001010010000101000011"== "1011010111010111111111010101100000000000101111101100011010011011" 

i want result true if string matches significant bits of string

to compare 1 msb, compare first character below:

boolean result = number1.charat(0) == number2.charat(0); 

for multiple msbs, use following code:

int noofmsbs = 8; boolean result = number1.substring(0, noofmsbs - 1).equals(number2.substring(0, noofmsbs - 1)); 

to compare if whole number present msb in string:

boolean result = number2.startswith(number1); 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -