Now, while I don't typically put much salt into the typical government conspiracy paranoia, this stuff about swine flu vaccinations containing live avian flu is... concerning. Add in the fact that Obama announced swine flu a national emergency just recently, despite mounting skepticism about its seriousness. Remember, take this stuff with a grain of salt, but still, be a little concerned:
Wednesday, November 11, 2009
Tuesday, November 10, 2009
Function to Print A Value's Bit Representation in Hex (by Casting as an Unsigned Int) in C
void printHex(int someInt)
{
unsigned int temp;
for(temp = (someInt); temp != 0; temp /= 16)
if(temp % 16 <>= 0)
printf("%d", temp % 16);
else
{
switch(temp % 16)
{
case 10:
putchar('A');
break;
case 11:
putchar('B');
break;
case 12:
putchar('C');
break;
case 13:
putchar('D');
break;
case 14:
putchar('E');
break;
case 15:
putchar('F');
break;
}
}
}
{
unsigned int temp;
for(temp = (someInt); temp != 0; temp /= 16)
if(temp % 16 <>= 0)
printf("%d", temp % 16);
else
{
switch(temp % 16)
{
case 10:
putchar('A');
break;
case 11:
putchar('B');
break;
case 12:
putchar('C');
break;
case 13:
putchar('D');
break;
case 14:
putchar('E');
break;
case 15:
putchar('F');
break;
}
}
}
Labels:
C,
Computer Science
Function for Printing An Item in Binary (Will Print in Little Endian) in C
void printBits(int someInt)
{
int counter, mask;
//Loop through the bits 1 by 1, putting out a 1 for every 1 encountered and a 0 for every 1 encountered
for(counter=1, mask=1; counter <= sizeof(int) * CHAR_BIT; counter++, mask*=2)
{
putchar(((someInt & mask)==0) ? '0' : '1');
//Put spaces between every 8 bits
if(counter != 0 && counter % (CHAR_BIT) == 0 && counter <= (sizeof(int) * CHAR_BIT))
putchar(' ');
}
printf("\n\n");
}
{
int counter, mask;
//Loop through the bits 1 by 1, putting out a 1 for every 1 encountered and a 0 for every 1 encountered
for(counter=1, mask=1; counter <= sizeof(int) * CHAR_BIT; counter++, mask*=2)
{
putchar(((someInt & mask)==0) ? '0' : '1');
//Put spaces between every 8 bits
if(counter != 0 && counter % (CHAR_BIT) == 0 && counter <= (sizeof(int) * CHAR_BIT))
putchar(' ');
}
printf("\n\n");
}
Labels:
C,
Computer Science
Function for Finding the Modulo of A Polynomial Without Having to Worry About Exponents
function modulo = modWOExp(a, n, z)
modulo = 1;
x = intDivision(a, z);
while n > 0
mod2 = intDivision(n, 2);
if mod2(2) == 1
modulo = modulo * x(2);
modZ = intDivision(modulo, z);
modulo = modZ(2);
end
mod2(1) = x(2) * x(2);
x = intDivision(mod2(1), z);
someTemp = intdivision(n, 2);
n = someTemp(1);
end
Labels:
Computer Science,
MATLAB
GCDPlus Function (Returns s & t for function gcd = sa + tb)
function sAndT = gcdPlus(a, b)
if a < b
temp = a;
a = b;
b = temp;
end
if b == 0
sAndT(1) = 1;
sAndT(2) = 0;
return;
end
q = intDivision(a, b);
r = q(2);
sAndTPrime = gcdPlus(b, r);
sAndT(1) = sAndTPrime(2);
sAndT(2) = sAndTPrime(1) - sAndTPrime(2) * q(1);
return;
Labels:
Computer Science,
MATLAB
Subscribe to:
Comments (Atom)