Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners JAVA leftshift operator add 1 instead of 0
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


J Modi
JAVA leftshift operator add 1 instead of 0
0 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners


Hi Guys,

I have a task to do. If I have some some int variable and If I apply left shift operator on that, it adds "0" on left side of value.

For example, view plaincopy to clipboardprint? byte a = 5, b;
int i;
i = a << 2;

So, it will work like this, 5 as binary : 0101 1st time left shift: 01010 2nd time left shift: 010100

So, the answer will be 20.

But, I want to have "1" instead of "0"s. So, it should have something like this..:

5 as binary : 0101 1st time left shift: 01011 2nd time left shift: 010111

So, the value should be 23.

How do I do this in java. Please help me asap.

Thanks. Code Eater.


Advertisement
View Answers

Related Tutorials/Questions & Answers:
JAVA leftshift operator add 1 instead of 0
JAVA leftshift operator add 1 instead of 0  Hi Guys, I have a task to do. If I have some some int variable and If I apply left shift operator... So, the answer will be 20. But, I want to have "1" instead of "0"s. So
Java XOR Operator
Bitwise XOR (exclusive or) "^" is a Java operator.... But  if both of the bits are same then the XOR operator gives the result 0. Following example will show how to use "^" operator in Java. XOR
Advertisements
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo C  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times
Java operator
Java operator  Which Java operator is right associative
Java operator
Java operator  What is the difference between the prefix and postfix forms of the ++ operator
Java operator
Java operator  What are the legal operands of the instanceof operator
how to search for string using LIKE operator instead of integer?
how to search for string using LIKE operator instead of integer?  ... instead of the itemid, and i want the itemname column to be in hyperlink not itemid... import="java.sql.*"%> <html> <table border="1"> <
error:Parameter index out of range (1 > number of parameters, which is 0).
error:Parameter index out of range (1 > number of parameters, which is 0).  my code:String org=request.getParameter("Org"); String desg=request.getParameter("des"); String From=request.getParameter("From"); String
How to add save as dialoguebox to export into excel instead of directly saving..
How to add save as dialoguebox to export into excel instead of directly saving..  Hello Sir, i followed ur tutorial to export into excel... directly but as per my need i have to add save as dialogue box to give user
Java "&" operator
Java "&" operator. In this section you will learn how to use "&" operator in java. Java provide six types of operators: among... in java. Bitwise operator work on bit and perform bit by bit operation
PHP Date add 1 year
to add 1 year easily. The code given below will show how you can add 1 year in php program. <?php //Example to add 1 year to a date object... Adding 1 year to a php date object is sometimes useful to solve some
Java Left Shift "<<" Operator
Java Left Shift "<<" Operator  ... Shift "<<" operator in Java. The Java programming language has... C:\unique>java leftshift << opeartor -9 << 3 = -72 9 <
Java Bitwise XOR "^" Operator
:\unique>java BitwiseXOR ^ XOR operator 1 ^ 0 = 1 C:\unique>... Java Bitwise XOR "^" Operator   ... "^" operator in Java. The Java programming language has operators
why we use constructors instead of methods in java?
why we use constructors instead of methods in java?   why we use constructors instead of methods in java
Assignment operator in java
Assignment operator in java Assignment operator is very common to almost all... the value to the variable lying on the left side. Java assignment operator... to be assigned to the variable to the left side. Assignment operator is also used
PHP Date add 1 day
PHP Date add 1 day This simple code will tell you how you can easily add 1 day to a date.  Example code for PHP Date add 1 day: <?php...;.$todayDate."<br>"; //Add one day to today $date = strtotime(date
PHP Date add 1 month
PHP Date add 1 month This example shows you how one month can be added... to add 1 month: <?php //PHP Example code to add one moth to a date...;.$todayDate."<br>"; //Add one day to today
Java Bitwise AND " &" Operator
:\unique>java BitwiseAND & AND operator 1 & 1 = 1 C... Java Bitwise AND " &" Operator   ... bitwise AND " &" operator in Java. The Java programming language has
Java Bitwise OR " |" Operator
BitwiseOR.java C:\unique>java BitwiseOR | OR opeartor 1 | 0... Java Bitwise OR " |" Operator   ...;|" operator in Java. The Java programming language has operators that perform
Java Questionmark operator
Java Questionmark operator        The only ternary (i.e. takes three values) operator in Java.... To know more about ternary operator http:/www.roseindia.net/java/master-java
Java bitwise OR "|" operator
Java bitwise OR "|" operator In this section you will learn about how to use" |" operator in java. Java provides six types of operators... are 0 then it will produce 0 but if one of the bit is 1 then it will produce 1
PHP Date add 1 hour
In the following example code we are showing how you can add one hour to a date object. <?php //This PHP Example code shows how to add one hour...;<br>".$currentTime; //Add one hour equavelent seconds 60*60
Java Bitwise NOT "~" Operator
Java Bitwise NOT "~" Operator   ... NOT "~" operator in Java. The Java programming language has operators...:\unique>java BitwiseNOT ~ NOT opeartor ~ 1 = -2 ~ 5 = -6
Java programming 1 - Java Beginners
Java programming 1  Thx sir for reply me ^^ err how bout if using scanner class or further method to solve that code? instead of using array?  ...://www.roseindia.net/java/java-tips/examples-introductory/console/console-input
array 1 - Java Beginners
array 1  WAP to input values in 2 arrays and merge them to array M... MergeArray{ public static int[] merge(int [] ... arr) { int arrSize = 0...[] result = new int[arrSize]; int j = 0; for (int[] array : arr
java code7 of 1
java code7 of 1  Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g ?· t in t time units
java code 8 of 1
java code 8 of 1  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
task 1 - Java Beginners
task 1  Please write a Java client that send a small letters string to a Java server which convert it to uppercase letters and send it back to the client. Please submit both the client and server programs  Hi Friend
que 1 - Java Beginners
que 1  WAP to enter a sentence & count the no. of times a particular word occurs in it.Display the frequency of the searched word. eg- input...(String[] args) { int count = 0; Scanner input = new
Advertisements
 

 

 

DMCA.com