Results 1 to 6 of 6
Thread: help in describe code
- 10-20-2011, 07:02 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 20
- Rep Power
- 0
help in describe code
hi, can you tell me what this code do?
is from binary add
Java Code:static String [] lookupTable = { "0+0+0=00", "0+0+1=01", "0+1+0=01", "0+1+1=10", "1+0+0=01", "1+0+1=10", "1+1+0=10", "1+1+1=11", }; static String lookup(char s1, char s2, char c) { String formula = String.format("%c+%c+%c=", s1, s2, c); for (String s : lookupTable) { if (s.startsWith(formula)) { return s.substring(s.indexOf("=") + 1); } } throw new IllegalArgumentException(); } static String zeroPad(String s, int length) { while (s.length() < length) { s = "0" + s; } return s; } static String add(String s1, String s2) { int length = Math.max(s1.length(), s2.length()); s1 = zeroPad(s1, length); s2 = zeroPad(s2, length); String result = ""; char carry = '0'; for (int i = length - 1; i >= 0; i--) { String columnResult = lookup(s1.charAt(i), s2.charAt(i), carry); result = columnResult.charAt(1) + result; carry = columnResult.charAt(0); } if (carry == '1') { result = carry + result; } return result; }
- 10-20-2011, 07:19 PM #2
Re: help in describe code
What happened when you ran it?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-20-2011, 08:08 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Re: help in describe code
Why did you ignore what I wrote in this thead: binary addition and Substraction?
kind regards,
JosLast edited by JosAH; 10-21-2011 at 06:11 PM. Reason: quoted the wrong person ...
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-21-2011, 09:14 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 20
- Rep Power
- 0
Re: help in describe code
because i am noob , and i cant do it, so i got this one, and i know how to put to subtration too, but why i can put with the options , with sum and sub?
- 10-21-2011, 05:46 PM #5
Re: help in describe code
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-21-2011, 06:05 PM #6
Member
- Join Date
- Oct 2011
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
My code was not executed properly.It will jumping to exception handling.my code is
By vinay4051 in forum EclipseReplies: 3Last Post: 08-10-2011, 09:17 AM -
servlet include method copying sorce code and executing source code as output how to
By shamkuma2k in forum Advanced JavaReplies: 0Last Post: 08-07-2011, 08:32 PM -
C server code - Java CLient Code _ TCP Connection Problem
By rmd22 in forum NetworkingReplies: 0Last Post: 02-21-2011, 11:50 AM -
Find difficulty to describe the page flows in a lengthy XML format
By rayethan in forum XMLReplies: 2Last Post: 04-01-2010, 12:55 PM -
[SOLVED] Please describe this code
By ezee in forum New To JavaReplies: 12Last Post: 03-18-2009, 05:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks