View

BinaryConstants

Page history last edited by 17 years, 5 months ago

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 needed, 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

BinaryConstants

Page Tools

Insert links

Insert links to other pages or uploaded files.

  1. Loading...
  1. No images or files uploaded yet.

Tip: To turn text into a link, highlight the text, then click on a page or file from the list above.

Comments (0)

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

Quantcast

AltStyle によって変換されたページ (->オリジナル) /