C - Data Type Hexadecimal Constants

Introduction

You can write integer values in hexadecimal form.

The hexadecimal int value is to base 16.

The digits in a hexadecimal number are the equivalent of decimal values 0 to 15.

They're represented by 0 through 9 and A though F (or a through f).

The hexadecimal numbers are written with the prefix 0x or 0X.

You would therefore write 9916 in your program as 0x99 or as 0X99.

Hexadecimal constants can also have a suffix.

Here are some examples of hexadecimal constants:

0xFFFF     0xdead     0xfade     0xFade     0x123456EE          

0xFABABULL is of type unsigned long long

0xafL is of type long.

Hexadecimal constants are most often used to specify bit patterns.

Each hexadecimal digit corresponds to four bits.

Two hexadecimal digits specify a byte.

The bitwise operators are usually used with hexadecimal constants that define masks.

Related Topics