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
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.....
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..
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.
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....
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
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.....
int i |= (0x7fffffff < 1);
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..
Now I know what is 8 bit mean. That's very cool.
If the point is only to turn a negative number positive why not simply use Math.abs() instead of this convoluted method?
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.
implementing vs learning
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....
There are 128. I can't like the video... Blame math, not me. 😢