Jump to content

diffrence beetween raw and hexadecimal output


birbal

Recommended Posts

i want to know what is the difference beetween the raw output and hexadecimel output in hash functions?

Link to comment
Share on other sites

i mean any difference in significancy beetween them?when the raw ouput being used?

Link to comment
Share on other sites

I don't know what you mean by "significancy". They are two different representations of the same numeric value. One is base-2, and one is base-16, you could convert that to base-10 also to get a regular integer. I don't know when you would want to return the binary value, you can do the same operations on the hex value (or convert it manually).

Link to comment
Share on other sites

ok thats what i wanted to know..thanksactually i thought to use binary output as password hash and store it in a binary field in db. so it will take lesser place than a hexadecimel. though as i did not use it before (raw) so i have some doubt on it. so just wanted to be sure. will it be right way? correct me please.

Link to comment
Share on other sites

i think i am missunderstanding the concept..but the character length are not same in hex and raw output..what does it mean then?

Link to comment
Share on other sites

It doesn't matter, because the amount of actual information they store is the same (as there are many more possible values for hexadecimal digits than binary digits). Of course, if you store the value using a string, then each character takes up a fixed amount of memory, and the shorter the string the better. However if you store it in binary, then each hexadecimal digit takes 4 bits to store, while each binary digit only takes one bit to store. Thus, you end up using the same amount of space in the end.In fact, I could use base 2160 and store a SHA-1 hash using only one "digit"! But that one digit will take up the same amount of space as if I had used base 16 or base 2.

Link to comment
Share on other sites

I think there's some misunderstanding here... I think birbal has a point...

If the optional raw_output is set to TRUE, then the sha1 digest is instead returned in raw binary format with a length of 20, otherwise the returned value is a 40-character hexadecimal number.
The 40 character string is a representation of a number.The 20 character string is the number itself, written out in binary, and interpreted as a string.The raw sha1() would indeed take less space than it's non raw hex representation. The only potential downfall is that if you're to use anything other than PHP (say, MySQL itself), you'd need to find a way to convert what may be a hex string into a raw string. I'm not aware if MySQL itself offers that, and AFAIK, some languages surely don't have such a thing built in. So... will the raw hash take less space? Yes. But it's not exactly best for portability.
Link to comment
Share on other sites

I think there's some misunderstanding here... I think birbal has a point...QUOTE (http://php.net/sha1)If the optional raw_output is set to TRUE, then the sha1 digest is instead returned in raw binary format with a length of 20, otherwise the returned value is a 40-character hexadecimal number.The 40 character string is a representation of a number.The 20 character string is the number itself, written out in binary, and interpreted as a string.The raw sha1() would indeed take less space than it's non raw hex representation. The only potential downfall is that if you're to use anything other than PHP (say, MySQL itself), you'd need to find a way to convert what may be a hex string into a raw string. I'm not aware if MySQL itself offers that, and AFAIK, some languages surely don't have such a thing built in. So... will the raw hash take less space? Yes. But it's not exactly best for portability.
thanks boen for clearing iti think mysql has some function to work with it...as bin(),hex(),conv()is there any need that i need to think about portability for other language? as the application intended for web use and which will interact with only php and mysql (as far now i can think)
Link to comment
Share on other sites

If you're willing to restrain yourself with only PHP being the client, then there's nothing to worry about. Your app will work in any PHP5+ version (since that's when the raw_output parameter was added).

Link to comment
Share on other sites

If you're willing to restrain yourself with only PHP being the client, then there's nothing to worry about. Your app will work in any PHP5+ version (since that's when the raw_output parameter was added).
thanks again for confirming.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...