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 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.

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
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"> <
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
Replication factor: 1 larger than available brokers: 0
Replication factor: 1 larger than available brokers: 0  Hi, I am...: 1 larger than available brokers: 0. [2017-12-09 14:25:42,460] ERROR... --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
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
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
python add 1 day to date
python add 1 day to date  Hi, In one of my project I am getting date from the some datasource and now I have to add one day to the date. How I can add 1 day to date in my Python program. Thanks   Hi, Here is example
Java Bitwise XOR "^" Operator
BitwiseXOR.java C:\unique>java BitwiseXOR ^ XOR operator 1 ^ 0... then this operator produces 0. Moreover if both of the bits are 1 i.e. 1^1 then also it produces... Java Bitwise XOR "^" Operator   
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... operator: OperatorExampleEquivalent expression +=a+=1a=a+1 -=a-=1a=a-1 *=a*=1a
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 Bitwise OR " |" Operator
operands are 1. However, if both of the bits are 0 then this operator produces 0... Java Bitwise OR " |" Operator   ...;|" operator in Java. The Java programming language has operators that perform
Java Left Shift "<<" Operator
Java Left Shift "<<" Operator  ... Shift "<<" operator in Java. The Java programming language has... leftshift.java C:\unique>java leftshift << opeartor -9 << 3
Java Bitwise AND " &" Operator
Java Bitwise AND " &" Operator   ... bitwise AND " &" operator in Java. The Java programming language has... are 0 or both of the bits are different then this operator produces 0
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... will be 1. But if both bit are 0 (0|0) it will produces 0. In more simple
Java Questionmark operator
Java Questionmark operator        The only ternary (i.e. takes three values) operator in Java... of the operator. To know more about ternary operator http:/www.roseindia.net/java
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 objectADS... Adding 1 year to a php date object is sometimes useful to solve some
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:ADS_TO_REPLACE_1...;Today: ".$todayDate."<br>"; //Add one day to today $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:ADS_TO_REPLACE_1 <?php //PHP Example code to add one... date echo "Today: ".$todayDate."<br>"; //Add one
Java Bitwise NOT "~" Operator
Java Bitwise NOT "~" Operator   ... NOT "~" operator in Java. The Java programming language has operators... BitwiseNOT.java C:\unique>java BitwiseNOT ~ NOT opeartor ~ 1
Why does Java not support operator overloading?
Why does Java not support operator overloading?  Hi, Why does Java not support operator overloading? thanks
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
instead of extend
instead of extend  Hi, I want answer this question. Ouestion: Instead of extends keyword,is there any keyword available in java? Regards krishna
instead of extend
instead of extend  Hi, I want answer this question. Ouestion: Instead of extends keyword,is there any keyword available in java? Regards krishna
Java 'or' operator
Java 'or' operator       OR operator is a kind of a conditional operators, which... between the two boolean expressions. The OR operator (|) is similar
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
PHP Date add 1 hour
In the following example code we are showing how you can add one hour... to add one hour to a date object $todayDate = date("Y-m-d g:i a"... into timeADS_TO_REPLACE_2 //echo "<br>".$currentTime; //Add one hour
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
javascript equality operator
javascript equality operator  javascript equality operator - What...;javascript equality operator Equal (==) Not equal (!=) Strict equal... the equality like .. '' == '0' // false 0 == '' // true 0 == '0
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
java program 1
java program 1  (4) WAP to take input of a String and check wheather it is valid number or not? Sample Output1: Enter a String : 10 10 is a number Sample Output2: Enter a String : 10b1 10b1 is not a number (5) WAP to take
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, Try
problem 1 - Java Beginners
problem 1   Hi, please help me!!!! How can i code in java using Two-dimensional Arrays? This question is related to the one i posted before. this is my input data file: 88 90 94 102 111 122 134 75 77 80 86 94 103 113 80
function 1 - Java Beginners
function 1  WAP to calculate the value of x,where x=tan(A)+tan(B)/1+tan(A)*tab(B)  Give more details like how to calculate and what is tan(A) and tan(B),etc
count occourance no of time no between 0 to 9 given by user in java
count occourance no of time no between 0 to 9 given by user in java  ...]; int i,temp=0; DataInputStream dis=new DataInputStream(System.in); for(i=0;i<9;i
Java programming 1 - Java Beginners
Java programming 1  hi there, Sir! Can u help me check where my...)); System.exit(0); } private static String getMarks(int[] numbers, int count) { int value[] = new int [count]; for (int i = 0; i <
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main... be at position 1, etc ?A sentence is constructed with a series of words? Index 0 1 2 3 4...); strAr[0] = word; stringResult +=" "+strAr[0]; for(int i=1;isentenceAr.length
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main... be at position 1, etc ?A sentence is constructed with a series of words? Index 0...? There are nine words in total Java has a standard to index elements starting
ArrayIndexOutOfBoundsException: 0
" java.lang.ArrayIndexOutOfBoundsException: 0 at jpcap.Jpcap.(Jpcap.java:34) at jpcap.Jpcap.main(Jpcap.java:155) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds) here is my code...ArrayIndexOutOfBoundsException: 0  I'am a newbie to java, i have
return 0 vs exit 0
return 0 vs exit 0  what is the difference between return 0 and exit 0 in c? i could not find any difference in their behaviour (both terminates the process execution) in a program
switch case instead of if else
switch case instead of if else  How to write code in switch case instead of if else in Java
Java programming 1 - Java Beginners
Java programming 1  thx sir for reply me..but sir can u pls simplify...; Hi friend, 1. Ask the user for their height. Convert it to a double... JTextField(4); // BMI BMIPanelDemo() { //Create button and add

Ads