Hashes 6 Make an integer positive

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 11

  • @ismaelE77
    @ismaelE77 Рік тому +2

    just simple note for more clarification : 0x7fffffff is hexa number
    0x7fffffff = 01111111111111111111111111111111
    Convert each hex digit to 4 binary digits (see conversion table below):
    7fffffff
    = 7 f f f f f f f
    = 0111 1111 1111 1111 1111 1111 1111 1111
    = 01111111111111111111111111111111
    In C and languages based on the C syntax, the prefix 0x means hexadecimal (base 16).
    java int is 32bit , but he was use 8bit just for example because its hard to write 32bit on the board
    also do not forget we use tows complement , so for example to get the bit representation of -5 you apply two's complement rule, that is: start from 5, flipped bits, add 1
    -5 -> 0000....0000000101 (5 in binary) -> 1111....1111111010 (flipped) -> 1111....1111111011 (+1)
    so that why -1 & 0x7fffffff return number like 268435455

  • @davidgeismar6531
    @davidgeismar6531 5 років тому +1

    Thanks for the lectures, they are great ! I really didnt get that bit about adding 07FFFFFFF to our output integer from the hashcode function though.....

    • @MrYourMedia
      @MrYourMedia 5 років тому

      int i |= (0x7fffffff < 1);

    • @samayam1526
      @samayam1526 4 роки тому

      int b=0b11111111111111111111111111111111; int c=0x7FFFFFFF;Integer d= b & c; this is what he is doing in that step . -1 in a 64 bit implementation is AND'ed with the 7F* gives the result that he has written..

  • @jianhe
    @jianhe 3 роки тому

    Now I know what is 8 bit mean. That's very cool.

  • @TZCoder
    @TZCoder 5 років тому +3

    If the point is only to turn a negative number positive why not simply use Math.abs() instead of this convoluted method?

    • @tyooca
      @tyooca 5 років тому +4

      Math.abs() inverts the signs of an integer by getting its bit representation, converting it to the one's compliment (which means to flip the binary bits ie. if 1011 = 0100) and adding 1 bit. If hashCode() were to return Integer.MIN_VALUE (which in binary is represented as a leading 1 with thirty one 0s) and you ran it through Math.abs(), the method would get the one's compliment (leading 0 with thirty one trailing 1s) and add 1 bit to it which would result in a leading 1 with thirty one 0s... which is Integer.MIN_VALUE.

    • @gnir6518
      @gnir6518 4 роки тому +3

      implementing vs learning

  • @davidgeismar6531
    @davidgeismar6531 5 років тому

    Im not an expert in math but it seems to me that the last step operation that consists of dividing by the size of the table and keeping the rest (the % operation) ends up in a very collision prone hashcode function....

  • @t3tu526
    @t3tu526 Рік тому +1

    There are 128. I can't like the video... Blame math, not me. 😢