I am trying to understand the part of the code presented here: stack overflow
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0;
var v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
I understand the issue of using the bitwise OR 0 to fill rooms that 3.142 | 0will return an integer, truncating a fraction, but I guess it comes to the use of a hexadecimal number, and lost when we And then or, for example randomNumber & 0x3 | 0x8.
I found that the method has a hexadecimal value toString(the number is not equal!):
0x3.toString() // returns '3'
And I guess that it probably randomNumber & 0x3 | 0x8returns a two-bit value, which is the ascii character (and not just a number) in the right range ... but I guess, and I can’t find a good link that gives me the whole picture.
- / ?
, JS : / hex
:
, , , qaru.site/questions/250/..., ..
, - String.fromCharCode()?