Hexadecimal and Octal Constants - C Data Type

C examples for Data Type:int

Introduction

The number system based on 8 is called octal and uses the digits 0 through 7.

In octal, the number 10 is the same as 8 in decimal.

The base 16 number system is called hexadecimal and uses the digits 0 through 9 plus the letters A through F, which stand for 10, 11, 12, 13, 14, and 15, respectively.

For example, the hexadecimal number 10 is 16 in decimal.

C allows you to specify integer constants in hexadecimal or octal instead of decimal.

A hexadecimal constant must consist of a 0x followed by the constant in hexadecimal form.

An octal constant begins with a 0. Here are some examples:

Demo Code

#include <stdio.h>

int main(void) {
   int hex = 0x80;              /* 128 in decimal */
   int oct = 012;               /* 10 in decimal */

   printf("%d", hex);

   printf("%d", oct);

   return 0;/*from  w ww  .j a va2  s. c  o m*/
}

Result


Related Tutorials