birbal Posted May 16, 2011 Share Posted May 16, 2011 I am trying to get the image ehader of png file which is encoded as binary and showing as some neeble. how can i convert it to hexadecimal ? i had tried with base_convert(() but it is not returing the expecte value as it is showing in a hex editor. What i am missing? Any help will be appriciated.thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted May 16, 2011 Share Posted May 16, 2011 http://php.net/manual/en/function.bin2hex.php Link to comment Share on other sites More sharing options...
birbal Posted May 16, 2011 Author Share Posted May 16, 2011 what is the difference beetween bin2hex() and using base_convert() specifying the base of binary and hexa decimal? is not both same? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 16, 2011 Share Posted May 16, 2011 They're probably the same. bin2hex might assume the number string is already in a certain format. Link to comment Share on other sites More sharing options...
birbal Posted May 16, 2011 Author Share Posted May 16, 2011 strangely it worked with bin2hex() but not with the base_convert() with specified base. I am not unable to understand the reason behind it.one more thing can the unpack() function be used to do extract from a binary data? it seems to me so. one related question with it..i saw a format option for pack() unpack() hexa with lower neeble and higher nebble..which is specified like 'h' and 'H'. how they both differ? i think it is also do that hexa convertion?thanks a lot for the help Link to comment Share on other sites More sharing options...
justsomeguy Posted May 17, 2011 Share Posted May 17, 2011 one more thing can the unpack() function be used to do extract from a binary data?Yes.i saw a format option for pack() unpack() hexa with lower neeble and higher nebble..which is specified like 'h' and 'H'. how they both differ?A nibble is half of a byte, or 4 bits, or one hex character. The low and high nibbles of a byte are the least significant 4 bits, and most significant 4 bits respectively. So for the byte 0x1a, 0xa is the low nibble and 0x1 is the high nibble. Link to comment Share on other sites More sharing options...
birbal Posted May 17, 2011 Author Share Posted May 17, 2011 A nibble is half of a byte, or 4 bits, or one hex character. The low and high nibbles of a byte are the least significant 4 bits, and most significant 4 bits respectively. So for the byte 0x1a, 0xa is the low nibble and 0x1 is the high nibble.and when the nibble order is significant? when it is being used? as for the normal flow high nibble will always come first. right? then when the 'h' is being used? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 17, 2011 Share Posted May 17, 2011 I can't really list all situations where you might use either nibble, but the main point is that you know how it is being formatted. You can tell it to format it however you want and then you know how it's structured so that you can handle it correctly. Link to comment Share on other sites More sharing options...
birbal Posted May 17, 2011 Author Share Posted May 17, 2011 ok, clearer now....and can you please little more elaborate this? bin2hex might assume the number string is already in a certain format.what do you mean by that? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 17, 2011 Share Posted May 17, 2011 What don't you understand about it? I'm not sure how else to say it. Link to comment Share on other sites More sharing options...
birbal Posted May 17, 2011 Author Share Posted May 17, 2011 you told that bin2hex assumed the string in certain format. what does the certain format means here? I am trying to understand why the bin2hex did the job but not the base_convert(). though it seems to me that it should work too. i am sure i am missing something vital concept here. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 17, 2011 Share Posted May 17, 2011 you told that bin2hex assumed the string in certain format. what does the certain format means here?I said it might, I'm just guessing. It would assume that the string is a binary string, where base_convert wouldn't necessarily assume that. What is the string you're starting with? Link to comment Share on other sites More sharing options...
birbal Posted May 17, 2011 Author Share Posted May 17, 2011 i am just pulling the image data using file_get_contents() . the string started with png recognation string which is in ASCII..showing as PNG (hex value of its showing 89 50 4e 47 the 89 showing as some nibble chracter) . is that the ASCII interupting this? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 17, 2011 Share Posted May 17, 2011 Everything is binary. ASCII just means the binary string is treated as a series of bytes, where each byte corresponds to a character on the ASCII table. It's still just binary though. Link to comment Share on other sites More sharing options...
birbal Posted May 19, 2011 Author Share Posted May 19, 2011 ok, i was confused with nibble character i thought it was interupted any other way rather than ASCII...but yesterday i saw that the nibble character is also is in ASCII table which i did not know.i still dont have any clue.so is there any answer of it why it was happening? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 20, 2011 Share Posted May 20, 2011 It's hard to say without testing everything myself. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.