Tuesday, March 22, 2011

converting decimals to binary & hex

Trying to keep brain from getting rusty... coded some simple functions in C that takes a decimal and spits out binary and hex.  Thought I might share it, enjoy!



#include
#include

void dec2bin(int dec);
void dec2hex(int dec);

int main(char *argv[])
{
    int i,j,num,tmp;

    scanf("%d",&num);
    printf("dec: %d\n",num);
    printf("bin: ");
    dec2bin(num);
    printf("\nhex: ");
    dec2hex(num);
}

void dec2bin(int dec)
{
    if (dec>0)
    {
        dec2bin(dec>>1);
        if (dec&1>=1)
            printf("1");
        else
            printf("0");
    }
}

void dec2hex(int dec)
{
    if (dec>0)
    {
        if (dec<10)
            printf("%d",dec);
        else if (dec>15)
        {
            dec2hex(dec/16);
            dec2hex(dec%16);
        }
        else
            printf("%c",dec-10+'A');
    }
    else
        printf("0");
}

Monday, March 7, 2011

using ipod shuffle under linux

I've been using gtkpod with my ipod shuffle.  A while ago, not sure what I have done when loading new songs into it, seems everything is corrupted, in gtkpod and hipo both shows the old songs, but when I play it there were only a few new songs available on the device and old ones were not in there.  Tried both gtkpod and hipo to delete the songs to start from fresh but had no luck.  At the end, command line tools does th trick, install gnupod-tools

gnupod_INIT -m /media/IPOD
gnucheck_--fixit -m /media/IPOD