Find the answer to your Linux question:
Results 1 to 8 of 8
Hi all, This my problem , i'm comparing hex values.... main(){ ::::: ::::: if(header[0]==0x47 && header[1]==0x49 && header[2]==0x46 && header[3]==0x38 ) printf("it's gif file"); ::: :: } ---- The program ...
  1. #1
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Question Hex comparision

    Hi all,
    This my problem , i'm comparing hex values....

    main(){
    :::::
    :::::
    if(header[0]==0x47 && header[1]==0x49 && header[2]==0x46 && header[3]==0x38 )
    printf("it's gif file");
    :::
    ::
    }

    ----
    The program works fine....
    i want to know....
    is the following is same as above one-i just appended ffffff ?
    please provide some info. regarding the usage of ffffff.

    if(header[0]==0xffffff47 && header[1]==0xffffff49 && header[2]==0xffffff46 && header[3]==0xffffff38 )
    ----------------

    Thanks guyz.
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    0x47 is not equal to 0xffffff47, try this:

    Code:
    printf("%d ; %d\n", 0x47, 0xffffff47);
    Regards

  3. #3
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    i should have tried this before posting here,

    if(0xffffff47==0x47 )
    printf("equal");
    else
    printf("nooooo");
    ---
    output:
    nooooo
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  4. #4
    Linux User
    Join Date
    Oct 2004
    Location
    /dev/random
    Posts
    404
    I think we have already discussed this here. Especially, the way you're trying to compare the GIF header doesn't look nice - I have already explained how standard headers should be compared for signatures.

    Moreover, as for the 0xffffff prefix,
    Code:
    0xf = 15 = 1111
    0xff = 255 = 1111 1111
    So logically concluding,
    Code:
    0xffffff47 = 1111 1111 1111 1111 1111 1111 0100 0111
    which is not the same as
    Code:
    0x47 = 0x00000047 = 0000 0000 0000 0000 0000 0000 0100 0111
    HTH
    The Unforgiven
    Registered Linux User #358564

  5. #5
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    f in hex is: 15 in decimal, 1111 in binary, 17 in octal. Are you a student or teaching yourself?

  6. #6
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    Quote Originally Posted by the_unforgiven
    I think we have already discussed this here. Especially, the way you're trying to compare the GIF header doesn't look nice - I have already explained how standard headers should be compared for signatures.

    Moreover, as for the 0xffffff prefix,
    Code:
    0xf = 15 = 1111
    0xff = 255 = 1111 1111
    So logically concluding,
    Code:
    0xffffff47 = 1111 1111 1111 1111 1111 1111 0100 0111
    which is not the same as
    Code:
    0x47 = 0x00000047 = 0000 0000 0000 0000 0000 0000 0100 0111
    HTH
    I was expecting reply from you
    Yes...you already explained me about how header are compared...
    creating structures for the header and proceed from there.
    But i'm in search of many file formats ( gif,jpeg,....) -
    so trying to fetch file types with help of headers only
    and not declaring specific structure of gif or jepg.because declaring structure for each file type is itself occupies space.
    How should i proceed?
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  7. #7
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    Quote Originally Posted by likwid
    f in hex is: 15 in decimal, 1111 in binary, 17 in octal. Are you a student or teaching yourself?
    .... i'm always a student
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  8. #8
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    Well I was gonna say maybe your instructor should have taken more time to explain the math behind it to you.. some professors are just weak. I had this one who was a mathematician, and he told us that couldn't figure how to set unix permissions in octal.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...