Prev: MAKE UPTO $5000 MONTHLY! $2000 INYOUR FIRST 30 DAYS!
Next: help: enum cause failure in multi thread run
From: Sanny on 14 Jul 2010 14:51 What about this case? if (Str.charAt(50)!='-') xx+=bit;bit=bit*2; if (Str.charAt(49)!='-') xx+=bit;bit=bit*2; if (Str.charAt(48)!='-') xx+=bit;bit=bit*2; if (Str.charAt(47)!='-') xx+=bit;bit=bit*2; if (Str.charAt(46)!='-') xx+=bit;bit=bit*2; if (Str.charAt(45)!='-') xx+=bit;bit=bit*2; if (Str.charAt(44)!='-') xx+=bit;bit=bit*2; if (Str.charAt(43)!='-') xx+=bit;bit=bit*2; if (Str.charAt(42)!='-') xx+=bit;bit=bit*2; if (Str.charAt(41)!='-') xx+=bit;bit=bit*2; if (Str.charAt(40)!='-') xx+=bit;bit=bit*2; if (Str.charAt(39)!='-') xx+=bit;bit=bit*2; if (Str.charAt(38)!='-') xx+=bit;bit=bit*2; if (Str.charAt(37)!='-') xx+=bit;bit=bit*2; if (Str.charAt(36)!='-') xx+=bit;bit=bit*2; if (Str.charAt(35)!='-') xx+=bit;bit=bit*2; if (Str.charAt(34)!='-') xx+=bit;bit=bit*2; if (Str.charAt(33)!='-') xx+=bit;bit=bit*2; if (Str.charAt(32)!='-') xx+=bit;bit=bit*2; if (Str.charAt(31)!='-') xx+=bit;bit=bit*2; if (Str.charAt(30)!='-') xx+=bit;bit=bit*2; if (Str.charAt(29)!='-') xx+=bit;bit=bit*2; if (Str.charAt(28)!='-') xx+=bit;bit=bit*2; if (Str.charAt(27)!='-') xx+=bit;bit=bit*2; if (Str.charAt(26)!='-') xx+=bit;bit=bit*2; if (Str.charAt(25)!='-') xx+=bit;bit=bit*2; if (Str.charAt(24)!='-') xx+=bit;bit=bit*2; if (Str.charAt(23)!='-') xx+=bit;bit=bit*2; if (Str.charAt(22)!='-') xx+=bit;bit=bit*2; if (Str.charAt(21)!='-') xx+=bit;bit=bit*2; if (Str.charAt(20)!='-') xx+=bit;bit=bit*2; if (Str.charAt(19)!='-') xx+=bit;bit=bit*2; if (Str.charAt(18)!='-') xx+=bit;bit=bit*2; if (Str.charAt(17)!='-') xx+=bit;bit=bit*2; if (Str.charAt(16)!='-') xx+=bit;bit=bit*2; if (Str.charAt(15)!='-') xx+=bit;bit=bit*2; if (Str.charAt(14)!='-') xx+=bit;bit=bit*2; if (Str.charAt(13)!='-') xx+=bit;bit=bit*2; if (Str.charAt(12)!='-') xx+=bit;bit=bit*2; if (Str.charAt(11)!='-') xx+=bit;bit=bit*2; if (Str.charAt(10)!='-') xx+=bit;bit=bit*2; if (Str.charAt(9)!='-') xx+=bit;bit=bit*2; if (Str.charAt(8)!='-') xx+=bit;bit=bit*2; if (Str.charAt(7)!='-') xx+=bit;bit=bit*2; if (Str.charAt(6)!='-') xx+=bit;bit=bit*2; if (Str.charAt(5)!='-') xx+=bit;bit=bit*2; if (Str.charAt(4)!='-') xx+=bit;bit=bit*2; if (Str.charAt(3)!='-') xx+=bit;bit=bit*2; if (Str.charAt(2)!='-') xx+=bit;bit=bit*2; if (Str.charAt(1)!='-') xx+=bit;bit=bit*2; if (Str.charAt(0)!='-') xx+=bit;bit=bit*2; Bye Sanny
From: Knute Johnson on 14 Jul 2010 14:53 On 7/14/2010 11:50 AM, Knute Johnson wrote: > On 7/14/2010 11:49 AM, Sanny wrote: >> On Jul 14, 11:40 pm, Knute Johnson<nos...(a)rabbitbrush.frazmtn.com> >> wrote: >>> On 7/14/2010 11:16 AM, Sanny wrote: >>> >>> >>> >>> >>> >>>> I use String comparision and if "str.charat() is not '-'" >>> >>>> We add bit value to xx. >>> >>>> The below code takes long time as we need to do 50 "if" comparisions >>>> each time the function is called. >>> >>>> Below is the sample Java Code: >>> >>>> ================================ >>> >>>> long xx=0; long bit=1; >>> >>>> if (Str.charAt(50)!='-') xx+=bit;bit++; >>>> if (Str.charAt(49)!='-') xx+=bit;bit++; >>>> if (Str.charAt(48)!='-') xx+=bit;bit++; >>>> if (Str.charAt(47)!='-') xx+=bit;bit++; >>>> if (Str.charAt(46)!='-') xx+=bit;bit++; >>>> if (Str.charAt(45)!='-') xx+=bit;bit++; >>>> if (Str.charAt(44)!='-') xx+=bit;bit++; >>>> if (Str.charAt(43)!='-') xx+=bit;bit++; >>>> if (Str.charAt(42)!='-') xx+=bit;bit++; >>>> if (Str.charAt(41)!='-') xx+=bit;bit++; >>>> if (Str.charAt(40)!='-') xx+=bit;bit++; >>>> if (Str.charAt(39)!='-') xx+=bit;bit++; >>>> if (Str.charAt(38)!='-') xx+=bit;bit++; >>>> if (Str.charAt(37)!='-') xx+=bit;bit++; >>>> if (Str.charAt(36)!='-') xx+=bit;bit++; >>>> if (Str.charAt(35)!='-') xx+=bit;bit++; >>>> if (Str.charAt(34)!='-') xx+=bit;bit++; >>>> if (Str.charAt(33)!='-') xx+=bit;bit++; >>>> if (Str.charAt(32)!='-') xx+=bit;bit++; >>>> if (Str.charAt(31)!='-') xx+=bit;bit++; >>>> if (Str.charAt(30)!='-') xx+=bit;bit++; >>>> if (Str.charAt(29)!='-') xx+=bit;bit++; >>>> if (Str.charAt(28)!='-') xx+=bit;bit++; >>>> if (Str.charAt(27)!='-') xx+=bit;bit++; >>>> if (Str.charAt(26)!='-') xx+=bit;bit++; >>>> if (Str.charAt(25)!='-') xx+=bit;bit++; >>>> if (Str.charAt(24)!='-') xx+=bit;bit++; >>>> if (Str.charAt(23)!='-') xx+=bit;bit++; >>>> if (Str.charAt(22)!='-') xx+=bit;bit++; >>>> if (Str.charAt(21)!='-') xx+=bit;bit++; >>>> if (Str.charAt(20)!='-') xx+=bit;bit++; >>>> if (Str.charAt(19)!='-') xx+=bit;bit++; >>>> if (Str.charAt(18)!='-') xx+=bit;bit++; >>>> if (Str.charAt(17)!='-') xx+=bit;bit++; >>>> if (Str.charAt(16)!='-') xx+=bit;bit++; >>>> if (Str.charAt(15)!='-') xx+=bit;bit++; >>>> if (Str.charAt(14)!='-') xx+=bit;bit++; >>>> if (Str.charAt(13)!='-') xx+=bit;bit++; >>>> if (Str.charAt(12)!='-') xx+=bit;bit++; >>>> if (Str.charAt(11)!='-') xx+=bit;bit++; >>>> if (Str.charAt(10)!='-') xx+=bit;bit++; >>>> if (Str.charAt(9)!='-') xx+=bit;bit++; >>>> if (Str.charAt(8)!='-') xx+=bit;bit++; >>>> if (Str.charAt(7)!='-') xx+=bit;bit++; >>>> if (Str.charAt(6)!='-') xx+=bit;bit++; >>>> if (Str.charAt(5)!='-') xx+=bit;bit++; >>>> if (Str.charAt(4)!='-') xx+=bit;bit++; >>>> if (Str.charAt(3)!='-') xx+=bit;bit++; >>>> if (Str.charAt(2)!='-') xx+=bit;bit++; >>>> if (Str.charAt(1)!='-') xx+=bit;bit++; >>>> if (Str.charAt(0)!='-') xx+=bit;bit++; >>> >>>> ================================ >>> >>>> Since most of the time taken is by the "if condition." >>> >>>> I am thinking of using >>> >>>> char mm='-'; >>>> int mm1=Character.getNumericValue(mm); >>> >>>> int mm2=Str.charAt(0); >>> >>>> int mm3=mm2-mm1; >>> >>>> Now if I subtract mm2-mm1=mm3 Then I have to have xx+=bit; only when >>>> mm3==0; >>> >>>> I want to write an Math Equation that computes mm3 and when mm3 value >>>> is "0" xx+=bit; is done. >>> >>>> I am not getting the clue how to develop this equation to get rid of >>>> the "If conditions" >>> >>>> Please suggest some equation or any other way to do this in one >>>> statement. >>> >>>> ENUMERATION? can these be used here to solve these "if conditions" in >>>> one step? >>> >>>> Bye >>>> Sanny >>> >>> public class test { >>> public static void main(String[] args) { >>> String str = "lkee-sli2<F2-8s0--slk3vUIGN_-"; >>> str = str.replaceAll("-",""); >>> int len = str.length(); >>> long xx = len * (len + 1) / 2; >>> System.out.println(xx); >>> } >>> >>> } >> >> That was just a sample. You have used Arithmetic Addition. >> >> Say the function is little complex. >> >> Below is the sample Java Code: >> >> ================================ >> >> long xx=0; long bit=1; >> >> if (Str.charAt(50)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(49)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(48)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(47)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(46)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(45)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(44)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(43)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(42)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(41)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(40)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(39)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(38)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(37)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(36)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(35)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(34)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(33)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(32)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(31)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(30)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(29)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(28)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(27)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(26)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(25)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(24)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(23)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(22)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(21)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(20)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(19)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(18)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(17)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(16)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(15)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(14)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(13)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(12)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(11)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(10)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(9)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(8)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(7)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(6)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(5)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(4)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(3)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(2)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(1)!='-') xx+=bit;bit=bit<<1; >> if (Str.charAt(0)!='-') xx+=bit;bit=bit<<1; >> >> >> ================================ >> >> What will you do in this case? >> >> Bye >> Sanny > > You should post what you want to know about. But this case is even > simpler, just shift bit the number of non - characters. > > bit << len; > I take that back. It is more complex but you still don't need all those if statements. -- Knute Johnson email s/nospam/knute2010/
From: Sanny on 14 Jul 2010 14:54 On Jul 14, 11:50 pm, Knute Johnson <nos...(a)rabbitbrush.frazmtn.com> wrote: > On 7/14/2010 11:49 AM, Sanny wrote: > > > > > > > On Jul 14, 11:40 pm, Knute Johnson<nos...(a)rabbitbrush.frazmtn.com> > > wrote: > >> On 7/14/2010 11:16 AM, Sanny wrote: > > >>> I use String comparision and if "str.charat() is not '-'" > > >>> We add bit value to xx. > > >>> The below code takes long time as we need to do 50 "if" comparisions > >>> each time the function is called. > > >>> Below is the sample Java Code: > > >>> ================================ > > >>> long xx=0; long bit=1; > > >>> if (Str.charAt(50)!='-') xx+=bit;bit++; > >>> if (Str.charAt(49)!='-') xx+=bit;bit++; > >>> if (Str.charAt(48)!='-') xx+=bit;bit++; > >>> if (Str.charAt(47)!='-') xx+=bit;bit++; > >>> if (Str.charAt(46)!='-') xx+=bit;bit++; > >>> if (Str.charAt(45)!='-') xx+=bit;bit++; > >>> if (Str.charAt(44)!='-') xx+=bit;bit++; > >>> if (Str.charAt(43)!='-') xx+=bit;bit++; > >>> if (Str.charAt(42)!='-') xx+=bit;bit++; > >>> if (Str.charAt(41)!='-') xx+=bit;bit++; > >>> if (Str.charAt(40)!='-') xx+=bit;bit++; > >>> if (Str.charAt(39)!='-') xx+=bit;bit++; > >>> if (Str.charAt(38)!='-') xx+=bit;bit++; > >>> if (Str.charAt(37)!='-') xx+=bit;bit++; > >>> if (Str.charAt(36)!='-') xx+=bit;bit++; > >>> if (Str.charAt(35)!='-') xx+=bit;bit++; > >>> if (Str.charAt(34)!='-') xx+=bit;bit++; > >>> if (Str.charAt(33)!='-') xx+=bit;bit++; > >>> if (Str.charAt(32)!='-') xx+=bit;bit++; > >>> if (Str.charAt(31)!='-') xx+=bit;bit++; > >>> if (Str.charAt(30)!='-') xx+=bit;bit++; > >>> if (Str.charAt(29)!='-') xx+=bit;bit++; > >>> if (Str.charAt(28)!='-') xx+=bit;bit++; > >>> if (Str.charAt(27)!='-') xx+=bit;bit++; > >>> if (Str.charAt(26)!='-') xx+=bit;bit++; > >>> if (Str.charAt(25)!='-') xx+=bit;bit++; > >>> if (Str.charAt(24)!='-') xx+=bit;bit++; > >>> if (Str.charAt(23)!='-') xx+=bit;bit++; > >>> if (Str.charAt(22)!='-') xx+=bit;bit++; > >>> if (Str.charAt(21)!='-') xx+=bit;bit++; > >>> if (Str.charAt(20)!='-') xx+=bit;bit++; > >>> if (Str.charAt(19)!='-') xx+=bit;bit++; > >>> if (Str.charAt(18)!='-') xx+=bit;bit++; > >>> if (Str.charAt(17)!='-') xx+=bit;bit++; > >>> if (Str.charAt(16)!='-') xx+=bit;bit++; > >>> if (Str.charAt(15)!='-') xx+=bit;bit++; > >>> if (Str.charAt(14)!='-') xx+=bit;bit++; > >>> if (Str.charAt(13)!='-') xx+=bit;bit++; > >>> if (Str.charAt(12)!='-') xx+=bit;bit++; > >>> if (Str.charAt(11)!='-') xx+=bit;bit++; > >>> if (Str.charAt(10)!='-') xx+=bit;bit++; > >>> if (Str.charAt(9)!='-') xx+=bit;bit++; > >>> if (Str.charAt(8)!='-') xx+=bit;bit++; > >>> if (Str.charAt(7)!='-') xx+=bit;bit++; > >>> if (Str.charAt(6)!='-') xx+=bit;bit++; > >>> if (Str.charAt(5)!='-') xx+=bit;bit++; > >>> if (Str.charAt(4)!='-') xx+=bit;bit++; > >>> if (Str.charAt(3)!='-') xx+=bit;bit++; > >>> if (Str.charAt(2)!='-') xx+=bit;bit++; > >>> if (Str.charAt(1)!='-') xx+=bit;bit++; > >>> if (Str.charAt(0)!='-') xx+=bit;bit++; > > >>> ================================ > > >>> Since most of the time taken is by the "if condition." > > >>> I am thinking of using > > >>> char mm='-'; > >>> int mm1=Character.getNumericValue(mm); > > >>> int mm2=Str.charAt(0); > > >>> int mm3=mm2-mm1; > > >>> Now if I subtract mm2-mm1=mm3 Then I have to have xx+=bit; only when > >>> mm3==0; > > >>> I want to write an Math Equation that computes mm3 and when mm3 value > >>> is "0" xx+=bit; is done. > > >>> I am not getting the clue how to develop this equation to get rid of > >>> the "If conditions" > > >>> Please suggest some equation or any other way to do this in one > >>> statement. > > >>> ENUMERATION? can these be used here to solve these "if conditions" in > >>> one step? > > >>> Bye > >>> Sanny > > >> public class test { > >> public static void main(String[] args) { > >> String str = "lkee-sli2<F2-8s0--slk3vUIGN_-"; > >> str = str.replaceAll("-",""); > >> int len = str.length(); > >> long xx = len * (len + 1) / 2; > >> System.out.println(xx); > >> } > > >> } > > > That was just a sample. You have used Arithmetic Addition. > > > Say the function is little complex. > > > Below is the sample Java Code: > > > ================================ > > > long xx=0; long bit=1; > > > if (Str.charAt(50)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(49)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(48)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(47)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(46)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(45)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(44)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(43)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(42)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(41)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(40)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(39)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(38)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(37)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(36)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(35)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(34)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(33)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(32)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(31)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(30)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(29)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(28)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(27)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(26)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(25)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(24)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(23)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(22)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(21)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(20)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(19)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(18)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(17)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(16)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(15)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(14)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(13)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(12)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(11)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(10)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(9)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(8)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(7)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(6)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(5)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(4)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(3)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(2)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(1)!='-') xx+=bit;bit=bit<<1; > > if (Str.charAt(0)!='-') xx+=bit;bit=bit<<1; > > > ================================ > > > What will you do in this case? > > > Bye > > Sanny > > You should post what you want to know about. But this case is even > simpler, just shift bit the number of non - characters. > > bit << len; The if Condition works only on "xx+=bit;" and "bit=bit<<1;" is outside the if condition. You may Change "bit=bit<<1;" into bit=bit*2; Then the conditions will be as follows. if (Str.charAt(50)!='-') xx+=bit;bit=bit*2; if (Str.charAt(49)!='-') xx+=bit;bit=bit*2; if (Str.charAt(48)!='-') xx+=bit;bit=bit*2; if (Str.charAt(47)!='-') xx+=bit;bit=bit*2; if (Str.charAt(46)!='-') xx+=bit;bit=bit*2; if (Str.charAt(45)!='-') xx+=bit;bit=bit*2; if (Str.charAt(44)!='-') xx+=bit;bit=bit*2; if (Str.charAt(43)!='-') xx+=bit;bit=bit*2; if (Str.charAt(42)!='-') xx+=bit;bit=bit*2; if (Str.charAt(41)!='-') xx+=bit;bit=bit*2; if (Str.charAt(40)!='-') xx+=bit;bit=bit*2; if (Str.charAt(39)!='-') xx+=bit;bit=bit*2; if (Str.charAt(38)!='-') xx+=bit;bit=bit*2; if (Str.charAt(37)!='-') xx+=bit;bit=bit*2; if (Str.charAt(36)!='-') xx+=bit;bit=bit*2; if (Str.charAt(35)!='-') xx+=bit;bit=bit*2; if (Str.charAt(34)!='-') xx+=bit;bit=bit*2; if (Str.charAt(33)!='-') xx+=bit;bit=bit*2; if (Str.charAt(32)!='-') xx+=bit;bit=bit*2; if (Str.charAt(31)!='-') xx+=bit;bit=bit*2; if (Str.charAt(30)!='-') xx+=bit;bit=bit*2; if (Str.charAt(29)!='-') xx+=bit;bit=bit*2; if (Str.charAt(28)!='-') xx+=bit;bit=bit*2; if (Str.charAt(27)!='-') xx+=bit;bit=bit*2; if (Str.charAt(26)!='-') xx+=bit;bit=bit*2; if (Str.charAt(25)!='-') xx+=bit;bit=bit*2; if (Str.charAt(24)!='-') xx+=bit;bit=bit*2; if (Str.charAt(23)!='-') xx+=bit;bit=bit*2; if (Str.charAt(22)!='-') xx+=bit;bit=bit*2; if (Str.charAt(21)!='-') xx+=bit;bit=bit*2; if (Str.charAt(20)!='-') xx+=bit;bit=bit*2; if (Str.charAt(19)!='-') xx+=bit;bit=bit*2; if (Str.charAt(18)!='-') xx+=bit;bit=bit*2; if (Str.charAt(17)!='-') xx+=bit;bit=bit*2; if (Str.charAt(16)!='-') xx+=bit;bit=bit*2; if (Str.charAt(15)!='-') xx+=bit;bit=bit*2; if (Str.charAt(14)!='-') xx+=bit;bit=bit*2; if (Str.charAt(13)!='-') xx+=bit;bit=bit*2; if (Str.charAt(12)!='-') xx+=bit;bit=bit*2; if (Str.charAt(11)!='-') xx+=bit;bit=bit*2; if (Str.charAt(10)!='-') xx+=bit;bit=bit*2; if (Str.charAt(9)!='-') xx+=bit;bit=bit*2; if (Str.charAt(8)!='-') xx+=bit;bit=bit*2; if (Str.charAt(7)!='-') xx+=bit;bit=bit*2; if (Str.charAt(6)!='-') xx+=bit;bit=bit*2; if (Str.charAt(5)!='-') xx+=bit;bit=bit*2; if (Str.charAt(4)!='-') xx+=bit;bit=bit*2; if (Str.charAt(3)!='-') xx+=bit;bit=bit*2; if (Str.charAt(2)!='-') xx+=bit;bit=bit*2; if (Str.charAt(1)!='-') xx+=bit;bit=bit*2; if (Str.charAt(0)!='-') xx+=bit;bit=bit*2; Bye Sanny
From: Sanny on 14 Jul 2010 14:58 > I take that back. It is more complex but you still don't need all those > if statements. > I agree. I want a simple equation instead of looking for 50 if conditions. Simple addition/ multiplication/ division will be faster than 50 if conditions. Since most of the time taken is by the "if condition." I am thinking of using char mm='-'; int mm1=Character.getNumericValue(mm); int mm2=Str.charAt(0); int mm3=mm2-mm1; Now if I subtract mm2-mm1=mm3 Then I have to have xx+=bit; only when mm3==0; I want to write an Math Equation that computes mm3 and when mm3 value is "0" xx+=bit; is done. I am not getting the clue how to develop this equation to get rid of the "If conditions" Please suggest some equation or any other way to do this in one statement. ENUMERATION? can these be used here to solve these "if conditions" in one step? Bye Sanny
From: Peter Duniho on 14 Jul 2010 15:06
Sanny wrote: > On Jul 14, 11:50 pm, Knute Johnson <nos...(a)rabbitbrush.frazmtn.com> > wrote: >> [...] >> You should post what you want to know about. But this case is even >> simpler, just shift bit the number of non - characters. >> >> bit << len; > > The if Condition works only on "xx+=bit;" and "bit=bit<<1;" is outside > the if condition. > > You may Change "bit=bit<<1;" into bit=bit*2; [...] With all of the various examples you've provided, it's very difficult to understand what the heck you are really trying to do. As Knute already said, you should explain _exactly_ what the goal here is. But, even a na�ve implementation of your original code or any variation thereof is far better than what you've posted. It's hard to even understand how someone who has any real experience programming has led themselves to essentially unroll a loop to the extent shown in your examples. What would be wrong with simply writing the code like this: long xx = 0, bit = 1; for (int i = 50; i >= 0; i--) { if (Str.charAt(i) != '-') { xx |= bit; } bit = bit << 1; } Or even (to micro-optimize a bit :) ): long xx = 0, bit = 1 << 50; for (int i = 0; i <= 50; i++) { if (Str.charAt(i) != '-') { xx |= bit; } bit = bit >> 1; } ? Pete |