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



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

Have Programming Question? Ask it here!
 
 
 


J Modi
JAVA leftshift operator add 1 instead of 0
0 Answer(s)      2 years and 7 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 are the legal operands of the instanceof operator
Java operator
Java operator  What is the difference between the prefix and postfix forms of the ++ 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 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
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 <
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 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
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
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
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
Why does Java not support operator overloading?
Why does Java not support operator overloading?  Hi, Why does Java not support operator overloading? thanks
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
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
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  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
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  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
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 programming 1 - Java Beginners
Java programming 1  Hi sir, i facing problem in this program. This program requires passing arrays as parameters and returning arrays from methods.../java/example/java/swing/ Thanks
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
EXCEPTIONS-----1 - Java Interview Questions
EXCEPTIONS-----1  How To Handle The Exceptions With Out Using Try,Catch And Throws?I Want Region Plz Post Answer
INTTERFACE 1 - Java Interview Questions
INTTERFACE 1  What is a Interface?  Hi Friend, Interface is the collection of methods with empty implementations and constants variables ( variables with static and final declarations ). All the methods
add new package java
add new package java  How to add new package in Java
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
Advertisements
 

 

 

DMCA.com