Addition/Substraction of Binary. Converting Binary to Integer

Hi,
I wanted to know how you can add or substract from a binary
value. Lets say xyz is binary now..... I want to convert 123 to
binary form and add or substract with xyz. Is this possible?
Finally I should be able to convert this new xyz i.e. after
addition or substraction to a number... please let me know what
should be done....
I have already looked @ ToString, tobase64,CharsetEncode,
BinaryEncode and dont think I would be able to use them before I
know that add/subs thing..
Thanks in advance...

Do you know anything about powers of 2?
first time through you get right most and multiply by 2^0
recurse using the binary string - right most char and an iteration value...
Here is a partial start for you:
public int binaryStringToInt(String bs, int i){
  //bs is binary string you with to convert
  //i is your itration variable
  int intValue = 0;
  if(bs.length=1){
    //your code here
  }else{
    binaryString(......);
  return intValue;
}

Similar Messages

  • Convert float to integer

    how to convert float to integer?
    and convert it back from integer to float?

    You can cast a float to an integer using the following syntax:
    float f = 1.245;
    int i = (int)f;
    To convert an int to a float you use a similar syntax:
    int i = 3;
    float f = (float)i;
    You'll also find some interesting methods for the Float and Integer object s in the Java API documentation.

  • Convert hexa to integer

    Hello,
    I have a flat file in which I get a value in hexadecimal format.
    Can we convert it in integer format in ODI ? I did'nt find anything about that.
    Thanks in advance
    Marie

    What is your target technology ?
    There are ways to do it. One of the way is to create function
    You can create ODI function to convert Hexadecimal to Integer.
    For example if you are using Oracle as your staging or target technology .. you can use
    Oracle you can use
    SYS_OP_RAWTONUM('AA') or to_number('AA', 'xx').
    Other can be directly using features of target or staging technologies to get the desired output.

  • Converting java's integer variable into mysql's tinyint datatype

    I am using mysql database and to store the values of the table I used tinyint as datatype in the mysql. I have to convert java's integer data type to mysql's tinyint data type. how it is possible. please help me out.
    Thanks ...

    Do you have to use int?
    The range of tinyint is -128 to 127, which matches the primitive byte data type in Java exactly. Maybe this primitive would be more suited to your needs? (sorry I have no advice on your actual question :p)
    Illu

  • Binary to integer?

    i know there are methods for this but im trying to figure out a way to do it recursively. i know how to get an integer to binary recursively (split it up into its remainder and it divided by 2), but im having a lot of trouble going the other way. any ideas?
    thanks!

    Do you know anything about powers of 2?
    first time through you get right most and multiply by 2^0
    recurse using the binary string - right most char and an iteration value...
    Here is a partial start for you:
    public int binaryStringToInt(String bs, int i){
      //bs is binary string you with to convert
      //i is your itration variable
      int intValue = 0;
      if(bs.length=1){
        //your code here
      }else{
        binaryString(......);
      return intValue;
    }

  • Converting 16 Bit Integer to Individual Bits

    I have a 16 bit Binary Integer and I need to convert this into Individual bits so we can perform some data manipulation.  I know there is a easy solution, but I just cant figure it out.  I attached what I was trying to do, remove the 16 bits and make a 1D array with 16 elements, then remove each element from the array.  This may be the wrong approach to this problem.  Any help would be appreciated.  Thanks in advance.

    It seems your input is a I16 integer, so it is really bad to have the representation of the control as U32. Makes no sense.
    Anyway, here's a quick alternative that seems to give the desired result with a code size of less than a postage stamp. see if it works for you.
    (note that we get different results for some input values. Do you have the original documentation for the conversion?)
    Message Edited by altenbach on 05-09-2007 10:25 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    scaleInteger.png ‏4 KB
    ScaleInteger.vi ‏38 KB

  • Convert string to integer

    package onjava;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import org.apache.soap.*;
    import org.apache.soap.rpc.*;
    import java.lang.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class CalcClient extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"");
    out.println("\"http://www.w3.org/TR/html4/loose.dtd\">");
    out.println("<html>");
    out.println("<head>");
    out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
    out.println("<title>Substraction using SOAP</title>");
    out.println("</head>");
        URL url = new URL ("http://localhost/soap/servlet/rpcrouter");
    Integer p1=request.getParameter("param1");
    Integer p2=request.getParameter("param2");
    In the above statement i have to convert the string to integer because that has to be passed in my program as an argument to a function so please let me know how to do that
        // Build the call.
        Call call = new Call();
        call.setTargetObjectURI("urn:onjavaserver");
        call.setMethodName("subtract");
        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
        Vector params = new Vector();
        params.addElement(new Parameter("p1", Integer.class, p1, null));
        params.addElement(new Parameter("p2", Integer.class, p2, null));
        call.setParams (params);
        // make the call: note that the action URI is empty because the
        // XML-SOAP rpc router does not need this. This may change in the
        // future.
        Response resp = call.invoke(url, "" );
        // Check the response.
        if ( resp.generatedFault() ) {
          Fault fault = resp.getFault ();
         out.println("The call failed: ");
         out.println("Fault Code   = " + fault.getFaultCode());
         out.println("Fault String = " + fault.getFaultString());
        else {
          Parameter result = resp.getReturnValue();
          out.println(result.getValue());
    out.println("</body>");
    out.println("</html>");

    Two possibilities: Try either java.lang.Integer.valueOf() or java.text.NumberFormat and its parse method.
    Either one will do what you want. I think Integer will be the simpler of the two.
    The code you have is obviously not correct, because getParameter returns a String:
    Integer p1=request.getParameter("param1");Do it like this:
    Integer p1=Integer.valueOf(request.getParameter("param1"));%

  • Converting String to integer?

    I looked on the sun forums and only found a lot of things that convert integers to Strings. Nothing to do the opposite.
    Does anyone know how I can convert a String to an int?

    coopkev2 wrote:
    an "A" from a "B"?? I don't understand what you are saying... I want to convert "100" to 100.
    Edit-- I'll be back soon.Read "A" as "Integer" and "B" as "String".
    In this case: read the [java.lang.Integer API|http://java.sun.com/javase/6/docs/api/java/lang/Integer.html] if there is a method which takes a String and returns an Integer or int.

  • How do I convert a condition integer to an object

    I have a condition integer for conditional text that is applied to text. How do I convert the integer to a Condition Format object? Thanks in advance.
    Rick Quatro

    Rick,
    It appears that Jang's idea is the general solution to converting an FDK object handle integer to an ES object. I imaging you were probably following this thread already, but this was the general answer to the same question about a document object.
    http://forums.adobe.com/message/4476098
    Russ

  • Convert decimal into integer

    Hello i think that's a simple question. I've to convert a decimal number (such as 0,1 ) into an integer number such as 0.
    What should i do? i tried with functions >> numeric >> conversions >> to long integers but i saw  it has only integers as input. 

    Not 100 percent sure what you wanted, so I've provided 3 alternatives.
    Mathematically rounds the number to the nearest whole value (integer)
    Divides the number by 1 (can be any constant, but for your case, 1 is used) and returns the quotient and remainder.  The quotient is the number as if it was rounded down to the nearest whole value (integer)
    Blindly converts your single precision (I assume this is your data type) to a long integer.  This will also get rid of the decimal place.
    I hope this helps.
    P.S.  Examples 1 & 2 use DBL precision values - these are interchangeable with SGL precision values, assuming you only need 1dp precision.
    Message Edited by James Mamakos on 05-11-2009 10:53 AM
    Never say "Oops." Always say "Ah, interesting!"
    Attachments:
    Nearest integer.JPG ‏5 KB
    Nearest multiple of 1.JPG ‏6 KB
    Blind conversion.JPG ‏7 KB

  • Converting Hex to Integer Value

    I'm trying to convert hex code to the corresponding integer, which can then be used to display a character.
    For example I have the code.
    int i = 0xE7;
    System.out.println(i);
    System.out.write(i)This produces the output as expected with the first output outputting 231, and the second line outputting the corresponding character.
    My problem comes when trying to make it so the hex code is variable.
    For example, I receive an output of 7
    This output is then the last digit of the hex code (so i check if needs to be converted to a, b etc.) then try and combine it with the prefix 0xE to create the hex code.
    I'm not quite sure how to do this bit as I cant carry out
    num = 7;
    hex = "0xE"+num;
    int i = hex;as the last line doesn't calculate due to hex being a string.
    Many thanks for your help.

    leesto wrote:
    The char array is currently being created using:
    char [] hexchar = "0123456789ABCDEF".toCharArray();
    Look this is OK, you need to do nothing but just the following:
    // I am using the very first example you provided
    // i is the index for the char
    String hex = "0E" + hexchar;
    Integer.parseInt(hex, 16);
    System.out.println(i);

  • How to convert Date to Integer

    Hi all,
    please send the code How to convert the Date to Integer
    I want like this
    example: Date= 04.11.2002 after conversion the integer is: 4112002
    like this I want if anyone knows this please send it as soon as possible
    byee
    thanks

    Assuming ... String ASimpleDateFormat;
    // do this first
    ASimpleDateFormat = ASimpleDateFormat.replace(".","");
    // then parse
    int DateAsInt = Integer.parseInt(ASimpleDateFormat);

  • Converting int[] to Integer[]

    How to convert an int array to Integer[] without iterating the int[]?
    we can traverse the int[] and add to Integer[]. But the traversing takes too much time. Is there any method to do the above conversion?

    If you are using 1.5, you can use the individual elements of the int[] as if they were an Integer, so why do you need to convert it? If it is to pass the array as an argument, then sorry, you are going to have to traverse the arrays and set the elements. And, at most, this will take a second or two of time (even if you have an array of nearly max size), so in what way is this "taking too much time"?
    Edit: And any API method to do this with a single line of code, would still, inside the method, need to traverse the arrays, so now time would be saved. If it is to save programming time, then take a few minutes to write a method for it now, and then every time you need it in the future, just use that method.

  • Convert Date to Integer

    I want to take this years number and convert it to an int.
    I have tried the following and i get errors saying it cannot resolve symbol: parseInt.
    Date thisyear = new Date();
    int thisyearint = Integer.parseInt(thisyear.getYear());
    Can anbody tell me how to di this simple conversion?
    Mossybreen

    It would help a great deal if you'd read the javadocs. If you had, you'd notice that the getYear() method in java.util.Date is deprecated. You shouldn't be using it.
    I think the proper way to do this is to use java.util.Calendar:
    Calendar calendar = new GregorianCalendar();
    int yearAsInt = calendar.get(Calendar.YEAR);See if that's better.
    MOD

  • Logic of converting strings to integer

    Hi all,
    I know that , I can convert a string into a number using API , Ineger.parseInt() . But i want to know the reall algoritham behind that
    .Can anybody explane that ?
    Basically I am interested in
      String s = "123";
      int i = Integer.parseInt(s);
      But i want to know what is the logic running behind this ?. Can anybody please help me. ...?
    Thanks in advance....

    The decompiled version parseInt() from Integer class
         * Parses the string argument as a signed decimal integer. The
         * characters in the string must all be decimal digits, except that
         * the first character may be an ASCII minus sign <code>'-'</code>
         * (<code>'&#92;u002D'</code>) to indicate a negative value. The resulting
         * integer value is returned, exactly as if the argument and the radix
         * 10 were given as arguments to the
         * {@link #parseInt(java.lang.String, int)} method.
         * @param s        a <code>String</code> containing the <code>int</code>
         *             representation to be parsed
         * @return     the integer value represented by the argument in decimal.
         * @exception  NumberFormatException  if the string does not contain a
         *               parsable integer.
        public static int parseInt(String s) throws NumberFormatException {
         return parseInt(s,10);
         * Parses the string argument as a signed integer in the radix
         * specified by the second argument. The characters in the string
         * must all be digits of the specified radix (as determined by
         * whether {@link java.lang.Character#digit(char, int)} returns a
         * nonnegative value), except that the first character may be an
         * ASCII minus sign <code>'-'</code> (<code>'&#92;u002D'</code>) to
         * indicate a negative value. The resulting integer value is returned.
         * <p>
         * An exception of type <code>NumberFormatException</code> is
         * thrown if any of the following situations occurs:
         * <ul>
         * <li>The first argument is <code>null</code> or is a string of
         * length zero.
         * <li>The radix is either smaller than
         * {@link java.lang.Character#MIN_RADIX} or
         * larger than {@link java.lang.Character#MAX_RADIX}.
         * <li>Any character of the string is not a digit of the specified
         * radix, except that the first character may be a minus sign
         * <code>'-'</code> (<code>'&#92;u002D'</code>) provided that the
         * string is longer than length 1.
         * <li>The value represented by the string is not a value of type
         * <code>int</code>.
         * </ul><p>
         * Examples:
         * <blockquote><pre>
         * parseInt("0", 10) returns 0
         * parseInt("473", 10) returns 473
         * parseInt("-0", 10) returns 0
         * parseInt("-FF", 16) returns -255
         * parseInt("1100110", 2) returns 102
         * parseInt("2147483647", 10) returns 2147483647
         * parseInt("-2147483648", 10) returns -2147483648
         * parseInt("2147483648", 10) throws a NumberFormatException
         * parseInt("99", 8) throws a NumberFormatException
         * parseInt("Kona", 10) throws a NumberFormatException
         * parseInt("Kona", 27) returns 411787
         * </pre></blockquote>
         * @param      s   the <code>String</code> containing the integer
         *                representation to be parsed
         * @param      radix   the radix to be used while parsing <code>s</code>.
         * @return     the integer represented by the string argument in the
         *             specified radix.
         * @exception  NumberFormatException if the <code>String</code>
         *              does not contain a parsable <code>int</code>.
        public static int parseInt(String s, int radix)
              throws NumberFormatException
            if (s == null) {
                throw new NumberFormatException("null");
         if (radix < Character.MIN_RADIX) {
             throw new NumberFormatException("radix " + radix +
                                 " less than Character.MIN_RADIX");
         if (radix > Character.MAX_RADIX) {
             throw new NumberFormatException("radix " + radix +
                                 " greater than Character.MAX_RADIX");
         int result = 0;
         boolean negative = false;
         int i = 0, max = s.length();
         int limit;
         int multmin;
         int digit;
         if (max > 0) {
             if (s.charAt(0) == '-') {
              negative = true;
              limit = Integer.MIN_VALUE;
              i++;
             } else {
              limit = -Integer.MAX_VALUE;
             multmin = limit / radix;
             if (i < max) {
              digit = Character.digit(s.charAt(i++),radix);
              if (digit < 0) {
                  throw NumberFormatException.forInputString(s);
              } else {
                  result = -digit;
             while (i < max) {
              // Accumulating negatively avoids surprises near MAX_VALUE
              digit = Character.digit(s.charAt(i++),radix);
              if (digit < 0) {
                  throw NumberFormatException.forInputString(s);
              if (result < multmin) {
                  throw NumberFormatException.forInputString(s);
              result *= radix;
              if (result < limit + digit) {
                  throw NumberFormatException.forInputString(s);
              result -= digit;
         } else {
             throw NumberFormatException.forInputString(s);
         if (negative) {
             if (i > 1) {
              return result;
             } else {     /* Only got "-" */
              throw NumberFormatException.forInputString(s);
         } else {
             return -result;
        }

Maybe you are looking for