this was supposed to be a simple stripped down BASE64 decoder done in java.
i don't (can't) use a lot of standard libraries because this App will be run on PDAs and java enabled cellphones, so SIZE does matter.
no problem, i get one of my contractors the BASE64 specs and some sample implementations ...
he's been fighting with this for 3 days now so i get his sourcefile and have a look at it this morning.
looks OK at first glance, but when you run it, it sporadically spits out wrong bytevalues while some decode just fine.
wtf?
so i spend all day going through his code (which is not that much) and i just can't figure out what's wrong.
then finally, about 15 minutes ago it dawns on me, have a look at this:
bReturn2[nn+2] = (byte)(iRes % 0xFF);
bReturn2[nn+1] = (byte)((iRes >> 8) % 0xFF);
bReturn2[nn+0] = (byte)((iRes >> 16) % 0xFF);
bReturn2 is a byte array, iRes a integer, the purpose is to roll the lower 3 bytes of the integer into 3 sequential fields in the byte array.
i had been staring at this for 6 hours and couldn't figure out what was wrong.
all the while it was right in front of me, plain sight, right there ...
can you find the error?
Andy
PS: did i mention that i HATE going through someone else code?
I have NFI, but I'd guess you're missing a parenthesis in the first line........but then again....I have NFI.
Get your broken off allen wrench out?
Sounds all Japanese to me!
Or ya got extra ones....parenthesis that is....
bReturn2[nn+2] = (byte)(iRes % 0xFF);
What are you calculating the remainder of? Are you dividing iRes and 0XFF somewhere else? It is hard to say without seeing the rest of the function.
QUOTE (Buzzard1 @ Aug 15 2005, 09:02 PM) |
I'd guess you're missing a parenthesis in the first line....... |
QUOTE (johnmhudson111 @ Aug 15 2005, 07:29 PM) |
Just a WAG since I have no coding ability, just an analyst by nature and that seems to be the missing pattern. |
QUOTE (Foxman @ Aug 15 2005, 07:29 PM) |
What are you calculating the remainder of? Are you dividing iRes and 0XFF somewhere else? It is hard to say without seeing the rest of the function. |
QUOTE (SirAndy @ Aug 15 2005, 09:32 PM) |
nope, nothing missing, syntax is just fine, compiles and runs without an error ... Andy |
I would have used the '&' operator instead of the '%' operator, but that's just me.
QUOTE (SirAndy @ Aug 15 2005, 08:33 PM) |
this was supposed to be a simple stripped down BASE64 decoder done in java. i don't (can't) use a lot of standard libraries because this App will be run on PDAs and java enabled cellphones, so SIZE does matter. no problem, i get one of my contractors the BASE64 specs and some sample implementations ... he's been fighting with this for 3 days now so i get his sourcefile and have a look at it this morning. looks OK at first glance, but when you run it, it sporadically spits out wrong bytevalues while some decode just fine. wtf? so i spend all day going through his code (which is not that much) and i just can't figure out what's wrong. then finally, about 15 minutes ago it dawns on me, have a look at this: bReturn2[nn+2] = (byte)(iRes % 0xFF); bReturn2[nn+1] = (byte)((iRes >> 8) % 0xFF); bReturn2[nn+0] = (byte)((iRes >> 16) % 0xFF); bReturn2 is a byte array, iRes a integer, the purpose is to roll the lower 3 bytes of the integer into 3 sequential fields in the byte array. i had been staring at this for 6 hours and couldn't figure out what was wrong. all the while it was right in front of me, plain sight, right there ... can you find the error? Andy PS: did i mention that i HATE going through someone else code? |
QUOTE (jonwatts @ Aug 15 2005, 07:37 PM) |
I would have used the '&' operator instead of the '%' operator, but that's just me. |
Dumb question. Is your input base10 or base16? It doesn't matter to the compiler but it makes a difference to us humans.
edit: nevermind ... modulus looked strange to me there, but it didn't register.
WOW, and I am such a suck-ass programmer too, but I do have to live in byte-stream land on a daily basis so maybe that helps.
I'd like to thank the Academy, my agent, and Andy for the beautiful 944 CV's, axles, and powder coated trailing arms (or do I just win an attaboy?).
QUOTE (ematulac @ Aug 15 2005, 08:08 PM) |
He's storing the bytes in the wrong order in the array. |
damn, I never thought about the input.
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)