Mercurial > hg > Members > masakoha > testcode
diff c/bitVector/main.cc @ 50:bb0e88fbbe02
impl bitGet and bitSet
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 May 2015 00:54:52 +0900 |
parents | f76fe618d5a7 |
children | 898e8d9e1c67 |
line wrap: on
line diff
--- a/c/bitVector/main.cc Mon May 25 20:46:26 2015 +0900 +++ b/c/bitVector/main.cc Tue May 26 00:54:52 2015 +0900 @@ -2,32 +2,32 @@ #include <stdlib.h> #include <string.h> -unsigned long bitContainer = 0x0000000000000000; -unsigned long bitMask = 0xFFFFFFFFFFFFFFFF; +unsigned long bitSet(int bitSetPosition, unsigned long bitContainer) { + unsigned long tmp = 1; + tmp = tmp << (63 - bitSetPosition); + bitContainer = bitContainer | tmp; + return bitContainer; +} -void bitSet(unsigned int bitShiftNum) { - bitContainer = 1 ; - bitContainer = bitContainer << (63 - bitShiftNum); - +void bitGet(unsigned long bitContainer) { for (int i = 63; i >= 0; i--) { printf( "%lu", ( bitContainer >> i ) & 1 ); } puts(""); } -void bitGet() { - -} - int main(int argc, char **argv) { - unsigned int bitShiftNum = 0; + int bitSetPosition = 0; + unsigned long bitContainer = 0; + for (int i = 1; i < argc ; i++) { if (strcmp(argv[i],"-n") == 0) { - bitShiftNum = atoi(argv[i+1]); + bitSetPosition = atoi(argv[i+1]); } } - bitSet(bitShiftNum); + bitContainer = bitSet(bitSetPosition,bitContainer); + bitGet(bitContainer); return 0; }