Hexadecimal Constants - C Data Type

C examples for Data Type:int

Introduction

You can write integer values in hexadecimal form which is in base 16.

The digits in a hexadecimal number are the equivalent of decimal values 0 to 15, and they're represented by 0 through 9 and A though F (or a through f in lower case).

Hexadecimal numbers are written with the prefix 0x or 0X.

9916 in decimal is 0x99 or 0X99 in hexadecimal form.

Hexadecimal constants can also have a suffix.

Here are some examples of hexadecimal constants:

Demo Code

#include <stdio.h> 
  
int main(void) 
{ 
    unsigned long long v = 0xFFFF;
    v = 0xdead;/*from   www  .  j  a va 2 s .  c o m*/
    v = 0xfade;
    
    printf("%d",v);
    
    v = 0xFade;
    
    printf("%d",v);
    
    v = 0x123456EE;
    
    printf("%d",v);
    
    v = 0xafL;
    
    printf("%d",v);
    
    v = 0xFABABULL;
    
    printf("%d",v);
    
    return 0;
}

Related Tutorials