Wednesday 28 February 2007

Using shift operator for faster division and multiplication

Multiplications

12 * 2 = 12 << 1
12 * 4 = 12 << 2
12 * 8 = 12 << 3
12 * 16 = 12 << 4
12 * 32 = 12 << 5
12 * 64 = 12 << 6
12 * 128 = 12 << 7
12 * 256 = 12 << 8

Divisions

12 / 2 = 12 >> 1
12 / 4 = 12 >> 2
12 / 8 = 12 >> 3
12 / 16 = 12 >> 4
12 / 32 = 12 >> 5
12 / 64 = 12 >> 6
12 / 128 = 12 >> 7
12 / 256 = 12 >> 8

Example


<?php
$a = 12 << 1;
print $a;
?>



Community discussing C and its derivatives like Win32, C++, MFC, C# tutorials - www.cfanatic.com

Sending files to browser in JSP

Sending files to browser in JSP

<%
// fetch the file
String filename = "companySecret.txt";
String filepath = "C:\\";

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + '"');

java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename);

int i;
while ((i=fileInputStream.read()) != -1)
{
out.write(i);
}

fileInputStream.close();
out.close();
%>



Community discussing C and its derivatives like Win32, C++, MFC, C# tutorials - www.cfanatic.com

Hello World!

Like all programming langues where we write a HelloWorld program when we start programming in that language, here's the HelloWorld to this Web Application Blog where you'll find lots of sample code snippets, tips n tricks for many poupular web development languages like PHP,Perl,Python,ASP,ASP.Net,Ruby,JSP,etc.