| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

BinaryConstants

This version was saved 15 years, 11 months ago View current version     Page history
Saved by Kenneth Finnegan
on May 5, 2008 at 9:59:31 pm
 

These macros will let you use binary constants straight in your code.  C normally only allows you to use base 8, 10, and 16.  Base 2 is extreamely useful when you're dealing with individual bits in a bitfield.

 

Code:

 binconst.h

 

Usage:

#include "binconst.h"

 

unsigned char bitfield = B8(01010101); // 85

unsigned int bigbitfield = B32(10000000,11111111,10101010,01010101); // 2164238933

 


Extensions:

If you wanted, it would be pretty trivial to create a 64 bit binary macro as well.  I'll leave that as an exercise for the reader.

 


Sources:

http://cprog.tomsweb.net/binconst.txt

Comments (0)

You don't have permission to comment on this page.