목록분류 전체보기 (36)
MS Jeong - Blog
/* binarySearch: find x in v[0]
/* rightRot: rotate x to right by n bit positions */ unsigned rightRot(unsigned x, unsigned n) { unsigned int temp, len, mostRight; for (temp = x, len = 1; (temp >>= 1); len++) { ; } mostRight = (1 > 1) | mostRight); } else { x >>= 1; } } return x; }
/* returns x with n bit starting at p inverted */ unsigned invert(unsigned x, int p, int n) { return (x ^ (~((~0)
/* returs x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged. */ unsigned setbits(unsigned x, int p, int n, unsigned y) { return ((x & ~(~((~0)
/* lower: convert c to lower case; ASCII only */ int lower(int c) { return ((c >= 'A') && (c
/* any(char [], char []): returns the first location in the string s1 where any character from the string s2 occurs */ /* if s1 contains no characters from s2, return (-1) */ int any(char s1[], char s2[]) { int i, j; for (i = 0; s1[i] != '\0'; i++) { for (j = 0; s2[j] != '\0'; j++) { if (s1[i] == s2[j]) { return i; } } } return (-1); }
/* htoi: convert hexdecimal string s to integer */ unsigned int htoi(const char s[]) { unsigned int i, n, temp; if ((s[0] != '0') || ((s[1] != 'x') && (s[1] != 'X'))) { return (-1); } i = 2; n = 0; while (1) { temp = s[i++]; if ((temp >= '0') && (temp
/* squeeze : deletes each character in c that matches any character in the string s */ void squeeze(char s[], char c[]) { int i, j, k; for (k = 0; (c[k] != '\0'); k++) { for (i = j = 0; (s[i] != '\0'); i++) { if (s[i] != c[k]) { s[j++] = s[i]; } } s[j] = '\0'; } return; }
for (i = 0; i < n; i++) { printf("%6d%c", a[i], ((i % 10) == 9) || (i == (n - 1)) ? '\n' : ' '); } printf("You have %d item%s", n, ((n == 1) ? "\n" : "s\n"));
/* In a two's complement number system, (x &= (x - 1)) deletes the rightmost 1-bit in x. */ int bitCount(unsigned int x) { int b; for (b = ((x == 0) ? 0 : 1); (x &= (x - 1)) != 0; b++) { ; } return b; }