![]() |
|
Porsche, and the Porsche crest are registered trademarks of Dr. Ing. h.c. F. Porsche AG.
This site is not affiliated with Porsche in any way. Its only purpose is to provide an online forum for car enthusiasts. All other trademarks are property of their respective owners. |
|
![]() ![]() |
![]() |
SirAndy |
![]()
Post
#1
|
Resident German ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 41,688 Joined: 21-January 03 From: Oakland, Kalifornia Member No.: 179 Region Association: Northern California ![]() |
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 ... (IMG:http://www.914world.com/bbs2/html/emoticons/headbang.gif) can you find the error? (IMG:http://www.914world.com/bbs2/html/emoticons/idea.gif) Andy PS: did i mention that i HATE going through someone else code? |
SpecialK |
![]()
Post
#2
|
aircraft surgeon ![]() ![]() ![]() ![]() Group: Benefactors Posts: 3,211 Joined: 15-March 04 From: Pacific, MO Member No.: 1,797 ![]() ![]() |
I have NFI, but I'd guess you're missing a parenthesis in the first line........but then again....I have NFI. (IMG:http://www.914world.com/bbs2/html/emoticons/confused24.gif)
Get your broken off allen wrench out? |
Midtowner |
![]()
Post
#3
|
Ooooo! ![]() ![]() ![]() Group: Members Posts: 652 Joined: 21-December 04 From: Sunnyvale, CA Member No.: 3,316 Region Association: None ![]() |
Sounds all Japanese to me! (IMG:http://www.914world.com/bbs2/html/emoticons/smile.gif)
|
Joe Bob |
![]()
Post
#4
|
Retired admin, banned a few times ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 17,427 Joined: 24-December 02 From: Boulder CO Member No.: 5 Region Association: None ![]() |
Or ya got extra ones....parenthesis that is....
|
Foxman |
![]()
Post
#5
|
Member ![]() ![]() Group: Members Posts: 57 Joined: 17-March 05 From: Fort Worth, TX Member No.: 3,778 ![]() |
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. |
johnmhudson111 |
![]()
Post
#6
|
||
Member ![]() ![]() Group: Members Posts: 491 Joined: 29-November 04 From: Nesbit, MS Member No.: 3,191 ![]() |
(IMG:http://www.914world.com/bbs2/html/emoticons/agree.gif) Just a WAG since I have no coding ability, just an analyst by nature and that seems to be the missing pattern. |
||
SirAndy |
![]()
Post
#7
|
||
Resident German ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 41,688 Joined: 21-January 03 From: Oakland, Kalifornia Member No.: 179 Region Association: Northern California ![]() |
nope, nothing missing, syntax is just fine, compiles and runs without an error ... (IMG:http://www.914world.com/bbs2/html/emoticons/wink.gif) Andy |
||
SirAndy |
![]()
Post
#8
|
||
Resident German ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 41,688 Joined: 21-January 03 From: Oakland, Kalifornia Member No.: 179 Region Association: Northern California ![]() |
this takes a 4 byte integer and zeros out all bits except the lowest 8 (0xff) and then stores those 8 bit in an byte-array. 1st line has no shift to get 1st byte 2nd line has 8 bit shift to get 2nd byte 3rd line has 16 bit shift to get 3rd byte that all is correct, but he still managed to f&%$ it up ... (IMG:http://www.914world.com/bbs2/html/emoticons/dry.gif) Andy |
||
johnmhudson111 |
![]()
Post
#9
|
||
Member ![]() ![]() Group: Members Posts: 491 Joined: 29-November 04 From: Nesbit, MS Member No.: 3,191 ![]() |
bReturn2[nn+2] = (byte)((iRes >> 4) % 0xFF); bReturn2[nn+1] = (byte)((iRes >> 8) % 0xFF); bReturn2[nn+0] = (byte)((iRes >> 16) % 0xFF); Nother WAG, I give up after this one (IMG:http://www.914world.com/bbs2/html/emoticons/happy11.gif) |
||
jonwatts |
![]()
Post
#10
|
no rules, just wrong ![]() ![]() ![]() ![]() Group: Benefactors Posts: 2,321 Joined: 13-January 03 From: San Jose, CA Member No.: 141 ![]() ![]() |
I would have used the '&' operator instead of the '%' operator, but that's just me.
|
r_towle |
![]()
Post
#11
|
||
Custom Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 24,591 Joined: 9-January 03 From: Taxachusetts Member No.: 124 Region Association: North East States ![]() ![]() |
bReturn2[nn+0] = (byte)(iRes % 0xFF); bReturn2[nn+1] = (byte)((iRes >> 8) % 0xFF); bReturn2[nn+2] = (byte)((iRes >> 16) % 0xFF); |
||
SirAndy |
![]()
Post
#12
|
||
Resident German ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 41,688 Joined: 21-January 03 From: Oakland, Kalifornia Member No.: 179 Region Association: Northern California ![]() |
we've got a winner! (IMG:http://www.914world.com/bbs2/html/emoticons/smilie_pokal.gif) he used the "%" operator which is MODULO instead of "&" which is bitwise AND ... took me 6 friggin hours to find that one! (IMG:http://www.914world.com/bbs2/html/emoticons/headbang.gif) Andy here's the correct code snippet: bReturn2[nn+2] = (byte)(iRes & 0xFF); bReturn2[nn+1] = (byte)((iRes >> 8) & 0xFF); bReturn2[nn+0] = (byte)((iRes >> 16) & 0xFF); |
||
jonwatts |
![]()
Post
#13
|
no rules, just wrong ![]() ![]() ![]() ![]() Group: Benefactors Posts: 2,321 Joined: 13-January 03 From: San Jose, CA Member No.: 141 ![]() ![]() |
Dumb question. Is your input base10 or base16? It doesn't matter to the compiler but it makes a difference to us humans.
|
ematulac |
![]()
Post
#14
|
914 addict ![]() ![]() ![]() Group: Members Posts: 540 Joined: 24-November 03 From: Palmdale, CA Member No.: 1,382 ![]() |
edit: nevermind ... modulus looked strange to me there, but it didn't register.
|
jonwatts |
![]()
Post
#15
|
no rules, just wrong ![]() ![]() ![]() ![]() Group: Benefactors Posts: 2,321 Joined: 13-January 03 From: San Jose, CA Member No.: 141 ![]() ![]() |
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?). |
SirAndy |
![]()
Post
#16
|
||
Resident German ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 41,688 Joined: 21-January 03 From: Oakland, Kalifornia Member No.: 179 Region Association: Northern California ![]() |
nope, java integer is reverse byte order, so that part was correct ... jon nailed it, see post above! (IMG:http://www.914world.com/bbs2/html/emoticons/type.gif) Andy |
||
Foxman |
![]()
Post
#17
|
Member ![]() ![]() Group: Members Posts: 57 Joined: 17-March 05 From: Fort Worth, TX Member No.: 3,778 ![]() |
damn, I never thought about the input.
|
![]() ![]() |
![]() |
Lo-Fi Version | Time is now: 16th June 2024 - 02:19 PM |
All rights reserved 914World.com © since 2002 |
914World.com is the fastest growing online 914 community! We have it all, classifieds, events, forums, vendors, parts, autocross, racing, technical articles, events calendar, newsletter, restoration, gallery, archives, history and more for your Porsche 914 ... |