00001 /*********************************************************** 00002 *PANALIX 0.06, (c) Adrian Panasiuk 2002-4 * 00003 *adek336[at]o2.pl, panalix.prv.pl * 00004 *under GPLv3 license * 00005 * * 00006 *panalix - small osdev project * 00007 ************************************************************ 00008 * bits.cpp, version 1.1 * 00009 ************************************************************ 00010 * * 00011 *primitive and naive bit operations, not very optimised. * 00012 * * 00013 *03'05'04- forked from o.05 branch.s bits.cpp(1.0) * 00014 * * 00015 ***********************************************************/ 00016 00017 #include "src/common/shared.hpp" 00018 #include "src/common/bits.hpp" 00019 00020 //returns the value of bit (which) in (n) 00021 char bit_val(char n, char which) 00022 { 00023 char x; 00024 /*the chosen bit is now 1*/ 00025 x = 1 << which; 00026 00027 /*use the mask*/ 00028 return (n & x) >> which; 00029 } 00030 00031 //returns (n) with bit (which) set to (what). 00032 char bit_set(char n, char which, char what) 00033 { 00034 /*bit (which) = (what), all other bits = 0*/ 00035 what = what << which; 00036 00037 /*mask excluding bit (which)*/ 00038 which = 0xFF - (1 << which); 00039 00040 /*masked n*/ 00041 n = n & which; 00042 00043 return n + what; 00044 } 00045 00046 //changes bit (which) in (*n) to (what). returns the value 00047 char bit_ptr(char *n, char which, char what) 00048 { 00049 char x; 00050 x = bit_set(*n, which, what); 00051 *n = x; 00052 return x; 00053 } 00054 00055 /***************************************************** 00056 * 00057 *panalix 0.04 (c) Adrian Panasiuk 2003 00058 *adek336[at]o2.pl, panalix.prv.pl 00059 * 00060 *****************************************************/