Use the most efficient method in Java to calculate 2 multiplied by 8

Source: Internet
Author: User

In Java, the most efficient way is to calculate the number equal to 2 multiplied by 8?
2 <3,
Because moving a number to the left is equivalent to multiplying it by the N power of 2. Then, if a number is multiplied by 8, you only need to shift it to the left by three places.
The bit operation CPU directly supports the highest efficiency. Therefore, the most efficient method of multiplying 2 by 8 is 2 <3.

// Calculate 2*8 = 2*23
System. Out. println (2 <3); // The third time of system. Out. println = 2 is 8.
// Calculate 2*16 = 2*24
System. Out. println (2 <4); // The four times of system. Out. println = 2 are 16.
// Calculate 3*8 = 2*23
System. Out. println (3 <3); // The third time of system. Out. println = 2 is 8.
// Calculate 5x8 = 5x23
System. Out. println (5 <3); // The third time of system. Out. println = 2 is 8.
// Calculate 6*4 = 6*22
System. Out. println (6 <2); // 2 times of 4 = 2 is 4

 

Javacode

Int I = 1;

System. Err. println (I-= I + = I-= I --);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.