Print Hexadecimal Values In Arduino - Tutorialspoint

  • Home
  • Whiteboard
  • Online Compilers
  • Practice
  • Articles
  • AI Assistant
  • Jobs
  • Tools
  • Corporate Training
  • Courses
  • Certifications
Menu Categories Login
  • Switch theme
  • SQL
  • HTML
  • CSS
  • Javascript
  • Python
  • Java
  • C
  • C++
  • PHP
  • Scala
  • C#
  • Tailwind CSS
  • Node.js
  • MySQL
  • MongoDB
  • PL/SQL
  • Swift
  • Bootstrap
  • R
  • Machine Learning
  • Blockchain
  • Angular
  • React Native
  • Computer Fundamentals
  • Compiler Design
  • Operating System
  • Data Structure and Algorithms
  • Computer Network
  • DBMS
  • Excel
Technical Questions and Answers
  • Data Structure Data Structure
  • Networking Networking
  • RDBMS RDBMS
  • Operating System Operating System
  • Java Java
  • MS Excel MS Excel
  • iOS iOS
  • HTML HTML
  • CSS CSS
  • Android Android
  • Python Python
  • C Programming C Programming
  • C++ C++
  • C# C#
  • MongoDB MongoDB
  • MySQL MySQL
  • Javascript Javascript
  • PHP PHP
  • 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 ArduinoArduino BoardsArduino IDEArduino Programming Language

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.

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.

Yash Sanghvi Yash Sanghvi Updated on: 2021-03-23T11:21:41+05:30

9K+ Views

Tag » Arduino Hex To Decimal Function