Bitwise operation result, strange behavior when ou

2019-05-31 06:41发布

问题:

It looks like my previous question update haven't been noticed, therefore a new question.

#dump1
var_dump('two identical strings' | 'two identical strings'); # mind the |
// string(21) "two identical strings"

#dump2
var_dump('two identical strings' ^ 'two identical strings'); # mind the ^
// string(21) ""

Why #dump2 shows that length == 21, but outputs none/invisible symbols?

Plus, when pasted in Notepad++ there are no signs of 21 symbols inside that string either, well actually, not even 1 symbol, as opposed to this output from different operation with unequal strings.
Those (DC3), (DC4) etc. didn't show up in browser, but shows up in Notepad++.

Oh, and actually, what are those blackish values inside that string? I'm guessing those are bit-level/assembler-level values, but, huh, guess !== true.

Thanks in advance!

回答1:

XORing a byte sequence with itself basically sets all bits to 0. So you have a long string of x00 bytes, which is the NUL character, which has no readable representation on screen. Doing bitwise operations on any sort of string will usually result in rather random bit sequences that can not be displayed on screen as readable characters. That random black stuff you see is Notepad++ trying its best to render a byte sequence.