What is the function of << (two Less than) in Java?

Asked

Viewed 22 times

2

I have the following method:

private static String encode(long number){
    StringBuilder builder = new StringBuilder();
    number = number  < 0 ? ~(number << 1) : number << 1;
    while (number >= 0x20) {
        builder.append(Character.toChars((int) ((0x20 | (number & 0x1f)) + 63)));
        number >>= 5;
    }
    builder.append(Character.toChars((int) (number + 63)));
    return builder.toString();
}

I would like help to try to understand the following parts:

number = number < 0 ? ~ (number << 1) number << 1;

((0x20 | (number & 0x1f)) + 63)

  • If I’m not mistaken you already have the answer to this here on the site. The problem is that the search does not recognize characters like < (which is why I edited)

  • I found this question after editing @jbueno http://stackoverflow.com/questions/1050989/double-greater-than-sign-in-java

  • 1
  • @bigown just ask the javascript utility is exact like in java?

  • @diegofm exactly. No language I know makes any different. It would practically say that arithmetic operations are different depending on the language.

  • 1

    @jbueno I think it would fit as duplicate too, it is a pity that the mechanism does not allow to choose more than one except when two people do it, which obviously does not happen when a moderator closes.

  • @bigown I have 1 more question, If you can help me ! O **~** do what? Thank you very much!]

  • I was going to vote as a duplicate, actually, but when I came back it was already marked @bigown

  • @Thiagoluizdomacoski Open another question. This has already been closed.

  • 1

    @ThiagoLuizDomacoski http://answall.com/q/1559/101

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.