I'm trying to learn more about encoding, I knew that CR
is 0x0d
in hex and LF
is 0x0a
but CRLF
is not 0x0d 0x0a
and not 0x0d0a
, I tried std::cout << std::hex << (int)'\r\n'
in C++ and the result was 0x0d
.
So, is CRLF
== CR
? and are these hex values the same on all operating systems?
Edit
The following is the result when tried on Windows 10 machine using MSVC (v16.2.0-pre.2.0)
const char crlf = '\r\n';
std::cout << std::hex << (int)crlf << std::endl;
std::cout << std::hex << (int)'\r\n' << std::endl;
std::cout << std::hex << (int)'\n\r' << std::endl;
output
d
a0d
d0a
Conclusion
CR
is char
and equals to 0x0d
in hex
LF
is char
and equals to 0x0a
in hex
CRLF
is a character sequence and it's equal CR
LF
seperatedly so it's equal to 0x0d
0x0a
in hex (as mentioned by @tkausl)
The explanation of the result I got is that const char crlf = '\r\n';
will be compiled to \n
(when compiled by MSVC)
when I looked at the assembly output I've found that comment ; 544 : // doing \r\n -> \n translation
thanks for all of the helpful comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With