Skip to content

x3hy/ebool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

ebool.h
--------------------------------------------------------------------
I'm often finding myself using many booleans in my various projects.
I've always wondered how much data a bool value is (from stdbool.h).
After some small tests I was able to conclude that a bool from
stdbool.h is in fact 8 bits, or one byte.

I think this is silly because you end up wasting 7 bits that you
will never use.

This library provides a new `ebool` datatype which allows you to
reference each individual bit of a bool.

Example:
--------------------------------------------------------------------
#define EBOOL_PROP uint8_t
#include "ebool.h"

ebool my_bools;

// (<ebool> <idx> <value>)
BSET(my_bools, 0, TRUE);  // set the 1st bit to TRUE
BSET(my_bools, 1, FALSE); // set the 2nd bit to FALSE
BSET(my_bools, 2, TRUE);  // set the 3rd bit to TRUE

// my_bools is now equal to 00000101u

printf ("%d, %d, %d\n",
	PART(my_bools, 0),
	PART(my_bools, 1),
	PART(my_bools, 2));

--------------------------------------------------------------------
OUTPUT:
1, 0, 1

About

A tiny library that allows access to all 8 bits of a boolean

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages