- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print hexadecimal values in Arduino
In order to print hexadecimal equivalents of numbers or characters, adding 'HEX' as the second argument of Serial.print() will be sufficient.
The following code demonstrates this −
Example
void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); Serial.println(75); Serial.println(75, HEX); Serial.println('A'); Serial.println('A',HEX); } void loop() { // put your main code here, to run repeatedly: }
The corresponding Serial monitor output is −
Now, the conversion of the decimal number 75 to a hexadecimal value is straightforward and you can even verify that 0x4B is the correct hexadecimal representation of 75. But what does the hexadecimal representation of 'A' mean?
Well, it is the hexadecimal representation of the number corresponding to A in the ASCII system. You can have a look at the ASCII table here: https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
As you can see, 'A' corresponds to number 65, whose hex representation would be 41.
Please note that hex representations do not work for floating point numbers. Serial.println(1.912,HEX); will only print 1.912.
- Related Articles
- Print binary values in Arduino
- Print plain text in Arduino
- Traditional C formatting in Arduino print
- Print new line and tab in Arduino
- Convert a string to hexadecimal ASCII values in C++
- Read values sent by Serial Monitor to Arduino
- Get max and min values of an array in Arduino
- How can we enter numeric values as Hexadecimal (HEX) number in MySQL statement?
- Print values of ‘a’ in equation (a+b)
- How to print the ASCII values in Golang?
- Haskell program to print ascii values
- C++ program to print values in a specified format
- Floating-point hexadecimal in Java
- Hexadecimal integer literal in Java
- Count Hexadecimal Number in C++
