Printing value in Decimal, Octal, Hexadecimal using printf in C (2024)

  • Home
  • DS & Algo. ▾
    • Data Structure
    • Algorithms
    • Coding Problems
  • Languages ▾
    • C
    • C++
    • C++ STL
    • Java
    • Python
    • Scala
    • Ruby
    • C#.Net
    • Golang
    • Android
    • Kotlin
    • SQL
  • Web. ▾
    • JavaScript
    • CSS
    • jQuery
    • PHP
    • Node.Js
    • AdonisJs
    • VueJS
    • Ajax
    • HTML
    • Django
  • Programs ▾
    • C
    • C++
    • Data Structure
    • Java
    • C#.Net
    • VB.Net
    • Python
    • PHP
    • Golang
    • Scala
    • Swift
    • Rust
    • Ruby
    • Kotlin
    • C Interview Programs
  • Aptitude ▾
    • C Aptitude
    • C++ Aptitude
    • Java Aptitude
    • C# Aptitude
    • PHP Aptitude
    • Linux Aptitude
    • DBMS Aptitude
    • Networking Aptitude
    • AI Aptitude
    • More...
  • Interview ▾
    • Golang
    • MIS Executive
    • DBMS
    • C
    • Embedded C
    • Java
    • SEO
    • HR
  • Find Output ▾
    • C
    • C++
    • C#.Net
    • Java
    • Go
    • PHP
    • More...
  • MCQs ▾
    • Web Technologie MCQs
    • CS Subjects MCQs
    • Databases MCQs
    • Programming MCQs
    • Testing Software MCQs
    • Digital Mktg Subjects MCQs
    • Cloud Computing S/W MCQs
    • Engineering Subjects MCQs
    • Commerce MCQs
    • More MCQs...
  • CS Subjects ▾
    • Machine Learning/AI
    • Operating System
    • Computer Network
    • Software Engineering
    • Discrete Mathematics
    • Digital Electronics
    • Data Mining
    • MIS
    • DBMS
    • Embedded Systems
    • Cryptography
    • CS Fundamental
    • More Tutorials...
  • More ▾
    • Tech Articles
    • Puzzles
    • Full Forms
    • Code Examples
    • Blogs
    • Guest Post
    • Programmer's Calculator
    • XML Sitemap Generator
    • About
    • Contact

Home »C solved programs »C basic programs

This code snippet will print an entered value in Decimal, Octal, and Hexadecimal format using printf() function in C programming language. By using different format specifier we can print the value in specified format.

Print value in Decimal, Octal ad Hex using printf() in C

/*Printing value in Decimal, Octal, Hexadecimal using printf in C.*/ #include <stdio.h> int main(){ int value=2567; printf("Decimal value is: %d\n",value); printf("Octal value is: %o\n",value); printf("Hexadecimal value is (Alphabet in small letters): %x\n",value); printf("Hexadecimal value is (Alphabet in capital letters): %X\n",value); return 0; }

Output

Decimal value is: 2567Octal value is: 5007Hexadecimal value is (Alphabet in small letters): a07Hexadecimal value is (Alphabet in capital letters): A07

Here, following format specifiers are used:

  • %d - to print value in integer format
  • %o - to print value in octal format
  • %x - to print value in hexadecimal format (letters will print in lowercase)
  • %X - to print value in hexadecimal format (letters will print in uppercase)

C Basic Programs »

C program to convert feet to inches

C program to print ASCII value of entered character

Related Programs

  • C program to find subtraction of two integer number
  • C program to find sum and average of two numbers
  • C program to print ASCII value of a character
  • C program to find cube of an integer number using two different methods
  • C program to find quotient and remainder
  • Program to calculate simple interest
  • Program to check whether number is EVEN or ODD
  • Program to find largest number among three numbers
  • C program to check whether a person is eligible for voting or not?
  • C program to read marks and print percentage and division
  • Program to find gross salary of an employee
  • C program to convert temperature from Fahrenheit to Celsius and vice versa
  • C program to calculate X^N (X to the power of N) using pow function
  • C program to find the difference of two numbers
  • C program to print size of variables using sizeof() operator
  • C program to demonstrate examples of escape sequences
  • C program to find area and perimeter of circle
  • C program to find area of a rectangle
  • C program to calculate HCF of two numbers
  • C program to multiply two numbers using plus operator
  • C program to demonstrate example of global and local scope
  • C program to demonstrate example of floor and ceil functions
  • Write a C program to evaluate the net salary of an employee given the following constraints
  • How to swap two numbers without using a temporary variable using C program?
  • C program to read name and marital status of a girl and print her name with Miss or Mrs
  • C program to check given number is divisible by A and B
  • C program to find sum of all numbers from 0 to N without using loop
  • Input hexadecimal value in C language
  • Printing an address of a variable in C
  • printf() statement within another printf() statement in C
  • printf() examples/variations in C
  • C program to calculate profit or loss
  • Calculate the distance between two cities from kilometers to meters, centimeters, feet and inches using C program
  • C program to find area and perimeter of the rectangle
  • C program to generate random numbers within a range
  • C Example to subtract two integers without using Minus (-) operator
  • C Example for different floating point values prediction
  • C Example for nested 'printf'
  • C program to get remainder without using % operator
  • C program to convert ascii to integer (atoi implementation)
  • C program to print ASCII table
  • C program to swap two numbers using four different methods
  • C program to check a given character is alphanumeric or not without using the library function
  • C program to check a given character is a digit or not without using the library function
  • C program to check a given character is a whitespace character or not without using the library function
  • C program to check a given character is an uppercase character or not without using the library function
  • C program to check a given character is a lowercase character or not without using the library function
  • C program to check a given character is a punctuation mark or not without using the library function
  • C program to check whether a character is a printable character or not without using library function
  • C program to convert a lowercase character into uppercase without using library function
  • C program to convert an uppercase character into lowercase without using library function
  • C program to print all punctuation marks without using library function
  • C program to print all punctuation marks using the ispunct() function
  • C program to print all printable characters using the isprint() function
  • C program to print all printable characters without using the library function
  • C program to make a beep sound
  • C program to convert a given number of days into days, weeks, and years
  • C program to find the roots of a quadratic equation
  • C program to find the GCD (Greatest Common Divisor) of two integers
  • C program to find the LCM (Lowest Common Multiple) of two integers
  • C program to calculate the area of a triangle given three sides
  • C program to calculate the area of a triangle given base and height
  • C program to calculate the area of Trapezium
  • C program to calculate the area of the rhombus
  • C program to calculate the area of Parallelogram
  • C program to calculate the area of Cube
  • C program to calculate the volume of Cube
  • C program to find the Surface Area and Volume of the Cylinder
  • C program to calculate the surface area, volume, and space diagonal of cuboids
  • C program to calculate the surface area, volume of Cone
  • C program to calculate the surface area, volume of the Sphere
  • C program to calculate the mean, variance, and standard deviation of real numbers
  • C program to read coordinate points and determine its quadrant
  • C program to calculate the value of nCr
  • C program to calculate the value of nPr
  • C program to calculate the product of two binary numbers
  • C program to calculate the addition of two complex numbers
  • C program to extract the last two digits from a given year
  • C program to perform the ATM Transactions
  • C program to read the height of a person and the print person is taller, dwarf, or average height person
  • C program to read the grade of student print equivalent description

Comments and Discussions!

Load comments ↻


Printing value in Decimal, Octal, Hexadecimal using printf in C (2024)

FAQs

How to print value in decimal octal hexadecimal using printf in C? ›

Print value in Decimal, Octal ad Hex using printf() in C

%d - to print value in integer format. %o - to print value in octal format. %x - to print value in hexadecimal format (letters will print in lowercase) %X - to print value in hexadecimal format (letters will print in uppercase)

How to convert decimal to octal and hexadecimal in C program? ›

You can use the octal literal (%o) and hexadecimal literal (%x).
  1. #include<stdio.h>
  2. void main()
  3. {
  4. int n = 33;
  5. printf("Decimal value = %d",n);
  6. printf("\nOctal value = %o",n);
  7. printf("\nHexadecimal value = %x",n);
  8. }
Jan 16, 2018

How to convert octal or hexadecimal to decimal in C? ›

Algorithm to Convert Octal to Decimal
  1. Initialize x = 0, ans = 0.
  2. Repeat the following steps while num > 0. Set -> y = num % 10, y will have last digit. Remove last digit of number in num variable -> num = num / 10. ans = ans + y * 8^x. updated vale of x varable by 1 till num > 0 -> x = x + 1.
  3. Return ans.
May 4, 2023

How do you convert decimals to octal and hexadecimal? ›

In decimal to binary, we divide the number by 2, in decimal to hexadecimal we divide the number by 16. In case of decimal to octal, we divide the number by 8 and write the remainders in the reverse order to get the equivalent octal number. Decimal Number: All the numbers to the base ten are called decimal numbers.

How to convert a decimal to hexadecimal in C? ›

Decimal to hexadecimal conversion
  1. Step 1: Start by entering the decimal number provided.
  2. Step 2: Divide the decimal value by 16.
  3. Step 3: Convert the remainder obtained in Step 2 to the equivalent hexadecimal digit. If the remaining is less than 10, the remainder should be used as the hexadecimal digit.
Jun 22, 2023

How to printf hex value in C? ›

Using %x format specifier in printf, we can print the hexadecimal values.

How to convert octal to hexadecimal without converting to decimal? ›

For example: consider a=3478. To get a hexadecimal representation without resorting to binary or decimal, you can use the fact that 8<16, i.e. just take the digits as they are. Now you just do the computation: hex(a)=7⋅80+4⋅81+3⋅82=716+2016+C016=E716.

How do you convert hexadecimal to octal with examples? ›

Hexadecimal to Octal Conversion
  1. Consider the given hexadecimal number.
  2. First count the number of digits in the number.
  3. If n is the position of the digit from the right end then multiply each digit with 16n-1
  4. Add the terms after multiplication.
  5. Resultant is the equivalent decimal form.
  6. Divide the decimal number with 8.

How to print octal value in C? ›

Printing the number in octal format

To print integer number in octal format, "%o" is used as format specifier in printf() statement.

How to print out a decimal in C? ›

You can control the number of digits after the decimal point when printing a floating point value using printf. For example, printf("The value is %10.6lf",myDoubleNum);

What to you use in printf () to display a hex value? ›

Using %x format specifier in printf, we can print the hexadecimal values.

How to print 8 digit hex in C? ›

To print integer number in Hexadecimal format, "%x" or "%X" is used as format specifier in printf() statement. "%x" prints the value in Hexadecimal format with alphabets in lowercase (a-f). "%X" prints the value in Hexadecimal format with alphabets in uppercase (A-F).

How to print a value in hex in C? ›

So, in order to print a hex number, you just need to take the number you want to print, 4 bits at a time, and convert it from the integer 0-15 to the characters '0' to '9' and then 'A' to 'F'. To get the number 4 bits at a time, you just shift and mask it, eg. uint8_t test = 0x3F //This is the number we want to print.

How do you print octal to decimal? ›

Arrange the octal number with the power of 8. Find the value of each of the numbers with exponents i.e. 80 is 1, 81 is 8, etc. Multiply each number. Add the product of all numbers to obtain the decimal number.

References

Top Articles
Min Pin Whippet Mix
West Virginia Scratch Off Codes
Marcial Quinones Useless MBA: 1500 applications & still no job!
Zuercher Portal Inmates Clinton Iowa
Leah4Sci Alkene Reactions
Pga Scores Cbs
Far-right activist Laura Loomer's access to Trump reveals a crisis in his campaign
Directions To Public Storage Near Me
LensCrafters Review for September 2024 | Best Contact Lens Stores
Best Jewelry Laser Engraving Machine to Elevate Your Design
Cbs Week 10 Trade Value Chart
Unveiling the Charm of Rio Vista, California
Yogabella Babysitter
Uhsbhlearn.com
Pokemon Infinite Fusion Good Rod
Bomei Massage
How Much Is Cvs Sports Physical
Ts Egypt Dmarco
Join MileSplit to get access to the latest news, films, and events!
9192464227
Noaa Marine Forecast Tampa
عکس کون زنان ایرانی
Truecarcin
Sufficient Velocity Quests
Tamilyogi. Vip
Central Nj Craiglist
All Obituaries | Dante Jelks Funeral Home LLC. | Birmingham AL funeral home and cremation Gadsden AL funeral home and cremation
Midsommar 123 Movies
Kawasaki Ninja® 500 | Motorcycle | Approachable Power
Act3: Walkthrough | Divinity Original Sin 2 Wiki
The Civil Rights Movement Crossword Review Answer Key
The Parking Point Jfk Photos
Strange World Showtimes Near Twin County Cinema
Rugrats in Paris: The Movie | Rotten Tomatoes
Rbgfe
Krunker.io . Online Games . BrightestGames.com
Jbz Inlog
Rage Room Longmont
Mercantilism - Econlib
History :: Town Of Saugerties
Directions To 401 East Chestnut Street Louisville Kentucky
Phrj Incarcerations
Moviesverse 2023
Hourly Weather Forecast for Amsterdam, North Holland, Netherlands - The Weather Channel | Weather.com
Joe Aloi Beaver Pa
Saratoga Otb Results
Dawat Restaurant Novi
June 21 2019 Algebra 2 Regents Answers
Classic Forbidden Romance: 6 Reasons To Watch C-Drama “Love Between Fairy And Devil”
Craigslist Org Sd Ca
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6129

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.