以前的偶数

时间:2015-12-10 17:42:02

标签: c++ optimization micro-optimization

如果整数不均匀(奇数),我想获得前一个数字,否则我想保留当前数字。例如。如果Connection.Response response = Jsoup.connect("http://www.itatonline.in:8080/itat/jsp/runBirt2.jsp?subAction=showReoprt&__report=CaseDetails1_DELHI.rptdesign&searchWhat=searchByAssName&Serial%20No=&Appeal%20No=&Assessee%20Name=&AssType=DontKnow&appealDate=&Bench=AGR").method(Method.GET).timeout(30000).execute(); String url = "http://www.itatonline.in:8080/itat/jsp/runBirt2.jsp?subAction=showReoprt&__report=CaseDetails1_DELHI.rptdesign&searchWhat=searchByAssName&Serial%20No=&Appeal%20No=&Assessee%20Name=k&AssType=DontKnow&appealDate=&Bench=AGR&__sessionId=20151210_231624_579"; String rawData = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/>" + "<soap:Body><GetUpdatedObjects xmlns=\"http://schemas.eclipse.org/birt\">" + "<Operation><Target><Id>Document</Id><Type>Document</Type></Target><Operator>GetPage</Operator><Oprand><Name>Appeal No</Name><Value></Value></Oprand><Oprand><Name>__isdisplay__AppealNo</Name><Value></Value></Oprand><Oprand><Name>Serial No</Name><Value></Value></Oprand><Oprand><Name>__isdisplay__Serial No</Name><Value></Value></Oprand><Oprand><Name>Assessee Name</Name><Value>k</Value></Oprand><Oprand><Name>__isdisplay__Assessee Name</Name><Value>k</Value></Oprand><Oprand><Name>searchWhat</Name><Value>searchByAssName</Value></Oprand><Oprand><Name>__isdisplay__searchWhat</Name><Value>searchByAssName</Value></Oprand><Oprand><Name>AssType</Name><Value>DontKnow</Value></Oprand><Oprand><Name>__isdisplay__AssType</Name><Value>DontKnow</Value></Oprand><Oprand><Name>appealDate</Name><Value></Value></Oprand><Oprand><Name>__isdisplay__appealDate</Name><Value></Value></Oprand><Oprand><Name>Bench</Name><Value>AGR</Value></Oprand><Oprand><Name>__isdisplay__Bench</Name><Value>AGR</Value></Oprand><Oprand><Name>__page</Name><Value>1</Value></Oprand><Oprand><Name>__svg</Name><Value>true</Value></Oprand><Oprand><Name>__page</Name><Value>1</Value></Oprand><Oprand><Name>__taskid</Name><Value>2015-11-9-23-16-22-34</Value></Oprand></Operation></GetUpdatedObjects></soap:Body></soap:Envelope>"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "text/xml; charset=UTF-8"); con.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); con.setRequestProperty("Cookie", response.cookies().toString().replaceAll("[{}]", "")); con.setRequestProperty("Host", "www.itatonline.in:8080"); con.setRequestProperty("Referer", "http://www.itatonline.in:8080/itat/jsp/runBirt2.jsp?subAction=showReoprt&__report=CaseDetails1_DELHI.rptdesign&searchWhat=searchByAssName&Serial%20No=&Appeal%20No=&Assessee%20Name=k&AssType=DontKnow&appealDate=&Bench=AGR"); con.setRequestProperty("SOAPAction", ""); con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:42.0) Gecko/20100101 Firefox/42.0"); con.setRequestProperty("X-Prototype-Version", "1.4.0"); con.setRequestProperty("X-Requested-With", "XMLHttpRequest"); con.setRequestProperty("request-type", "SOAP"); // Send post request con.setDoOutput(true); OutputStreamWriter w = new OutputStreamWriter(con.getOutputStream(), "UTF-8"); w.write(rawData); w.close(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer resp = new StringBuffer(); while ((inputLine = in.readLine()) != null) { resp.append(inputLine); } in.close(); System.out.println(resp); ,我想将x = 3分配给2,如果x,则不会发生任何事情。

目前,我执行以下操作:x = 4,但我听说该划分计算费用昂贵。 x = (x/2)*2是否会优化此表达式?我正在使用-O3编译器。 c++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4x

1 个答案:

答案 0 :(得分:2)

尝试以下

x &= ~1;

我认为x被声明为具有类型int。否则,如果类型x的等级大于int类型的等级,则应使用变量x类型的整数文字。