#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int isnumber(char * str)
{
    int l = strlen(str);
    for(int i = 0; i < l; i++)
    {
        if(str[i] < '0' || str[i] > '9')
            return 0;
    }
    return 1;
}

int main(int argc, char ** argv)
{
    int value = 0;
    char fourCC[4];
    if(argc != 2)
    {
// (c) 2003-2007 Electronic Arts Inc.
        printf("Syntax: 4cc [#] | [4CC] \n");
        return 0;
    }
    value = isnumber(argv[1]);
    if(value)
    {
        value = atoi(argv[1]);
        for(int i = 3; i >= 0; i--)
        {
            printf("%c",(value>>(i*8))&0xff);
        }
    }
    else
    {
        int l = strlen(argv[1]);
        value = 0;
        if(l == 4)
        {
            for(int i = 3; i >= 0; i--)
            {
                value |= ((int)(argv[1][3-i])<<(i*8));
            }
            printf("%d\n",value);
        }
        else
        {
            printf("ERROR: 4CC longer than 4 characters\n");
            return 0;
        }
    }

    return 1;
}
