Shurikn Posted June 9, 2005 Posted June 9, 2005 this is pretty simple really... what i need is to compare some byte array obtain from the header of a file, to decimal value (to verify the signature) and unfortunatly, the 4 first byte of a jpg are not chars... they are plain hex value, wich Is why i need to do this, here's what I go so far: if(entete.SOI!=0xFFD8) { return 0; } if(entete.JFIFMarker!=0xFFE0) { return 0; } but the problem is that 0xFFD8 is seen as an integer and entete.SOI is a byte[2] so he wont compare them, so is there a way to: 1-change a byte array into integers 2-change an int into a byte array... 3 something else Quote
IngisKahn Posted June 9, 2005 Posted June 9, 2005 Sure there's a number of ways to do it. You can shift and or them together or better yet use a pointer to copy the value. But the real question is why is SOI a byte array in the first place? It seems better suited to be an int or short. Generally you shouldn't expose arrays publically anyway. Quote "Who is John Galt?"
Shurikn Posted June 9, 2005 Author Posted June 9, 2005 well it's a structure so everything is just public in it... puting it as a short is a good idea... that's what i'll do. but just for my personal (and others) knowledge, how would you do it? You can shift and or them together or better yet use a pointer to copy the value. Quote
IngisKahn Posted June 9, 2005 Posted June 9, 2005 Are you reading this from a stream? Just use BinaryReader.ReadInt16() in that case. But anyway, here's 2 ways to convert a byte[2] array into a short: short s = (short)((b[1] << 8) | b[0]); or in an unsafe block: fixed (byte* pb = b) s = *(short*)pb; Quote "Who is John Galt?"
Shurikn Posted June 9, 2005 Author Posted June 9, 2005 (edited) thanks, but just so someone reading this thread dont do mistake, using a short here wont work, because the value of 0xFFD8 =65496 and a shot stop at 32767, so a ushort (unsigned short) need to be used Edited June 9, 2005 by Shurikn Quote
IngisKahn Posted June 9, 2005 Posted June 9, 2005 Using short or ushort dosen't really make a difference. The short will just show up as a two's compliment negative number. Quote "Who is John Galt?"
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.