Mercurial > hg > Members > masakoha > testcode
changeset 49:f76fe618d5a7
implement bitset
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2015 20:46:26 +0900 |
parents | 010ae96a3e4e |
children | bb0e88fbbe02 |
files | c/bitVector/main.cc |
diffstat | 1 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/c/bitVector/main.cc Mon May 25 14:53:47 2015 +0900 +++ b/c/bitVector/main.cc Mon May 25 20:46:26 2015 +0900 @@ -1,6 +1,33 @@ #include <stdio.h> +#include <stdlib.h> +#include <string.h> + +unsigned long bitContainer = 0x0000000000000000; +unsigned long bitMask = 0xFFFFFFFFFFFFFFFF; + +void bitSet(unsigned int bitShiftNum) { + bitContainer = 1 ; + bitContainer = bitContainer << (63 - bitShiftNum); -int main(int argc, char *argv[]){ + 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; + for (int i = 1; i < argc ; i++) { + if (strcmp(argv[i],"-n") == 0) { + bitShiftNum = atoi(argv[i+1]); + } + } + + bitSet(bitShiftNum); return 0; }