按位运算结果,输出时行为异常 [英] Bitwise operation result, strange behavior when outputted

查看:39
本文介绍了按位运算结果,输出时行为异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我的上一个问题尚未更新注意到了,因此是一个新问题.

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) ""

为什么#dump2 显示长度== 21,却不输出/看不见的符号?

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

此外,在Notepad ++中粘贴时,该字符串中也没有21个符号的迹象,实际上,甚至没有1个符号,这与使用不相等字符串的不同操作的输出相反.
那些(DC3)(DC4)等不在浏览器中显示,但在Notepad ++中显示.

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++.

哦,实际上,该字符串中的那些黑色值是什么?我猜这些是位级/汇编级的值,但是, guess!== true .

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.

推荐答案

将字节序列与自身进行异或运算,基本上会将所有位设置为0.因此,您有一个x00字节的长字符串,这是 NUL 字符,在屏幕上没有可读的表示形式.对任何类型的字符串进行按位运算通常会导致相当随机的位序列,无法以可读字符的形式在屏幕上显示.您看到的那些随机的黑色东西是Notepad ++尽力呈现字节序列.

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.

这篇关于按位运算结果,输出时行为异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆