Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is CRLF in hex?

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
like image 449
Ahmed Kamal Avatar asked Sep 19 '25 08:09

Ahmed Kamal


1 Answers

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

like image 162
Ahmed Kamal Avatar answered Sep 20 '25 20:09

Ahmed Kamal