🚀 Learn 90+ coding courses & crack 200+ competitive exams — powered by learning intelligence on Leyaa.ai →
How to print hexadecimal in c
Using %x format specifier in printf, we can print the hexadecimal values.
%x
%x will print the hexadecimal in small letters.
Like, aaff2, ffd etc.
Example
#include<stdio.h> int main() { int i = 255; printf("255 in hexadecimal = %x\n",i); return 0; }
Output
255 in hexadecimal = ff
%X
%X will print the hexadecimal in capital letters.
Like, AAFF2, FFD etc.
Example
#include<stdio.h> int main() { int i = 255; printf("255 in hexadecimal = %X\n",i); return 0; }
Output
255 in hexadecimal = FF
Useful Resources
https://www.log2base2.com/number-system/hexadecimal-number-system.htmlhttps://www.log2base2.com/number-system/hex-to-decimal.html
🚀 Your coding + exam prep journey starts here
Learn Python, C, Java, SQL & 90+ technologies. Practice for IBPS, SSC, Railway & 200+ exams. All powered by AI. All free.
Get Started on Leyaa.ai →