April 16, 2022 11:42 pm GMT
Data type
Hexadecimal (hex for short) representation uses
Original Link: https://dev.to/hwangs12/c-axioms-36oa
C Axioms
My note for c++
1.1.1
Data type char16_t
, char32_t
, or wchar_t
with variables assigned to an octal representation of unicode characters are converted to a decimal when used with std::cout
while char
in Octal representation is converted to a string literal.
Example
#include <iostream>int main(){ // The following are Octal representation of // a unicode character M. char16_t d1 = '\115'; char32_t d2 = '\115'; wchar_t d3 = '\115'; char d4 = '\115' std::cout << d1 << " is the \x4d greatest number of all" << std::endl; // d1, d2, d3 are converted to decimal, hence shows 77 // in the output but d4 will be converted to character M. return 0;}
1.1.2
Hexadecimal (hex for short) representation uses A, B, C, D, E, F
to represent numbers after 9. For example, 4D in hex is equivalent to 77 in decimal because D is equal to 13 and 4 * 16 + 13 = 77
.
Example
#include <iostream>int main(){ char16_t yo = '\x4d'; // char16_t type converts to hex int with std::cout per 1.1.1 std::cout << yo << " is the greatest number of all " << std::endl; // 77 is the greatest number of all return 0;}
Note: Had A B C D E F
not been used, it would have been more difficult to represent decimal numbers like 77 because \x4(13)
is longer in length, and without the brackets, it will convert to a much bigger number.
Original Link: https://dev.to/hwangs12/c-axioms-36oa
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To