Converting a long to a byte

Hi,
Is there any way to convert a long to a byte. will byteValue() help?i have tried with it, but i get an error saying "long cannot be dereferenced.
long tag = 1231200;
byte[] newtag = tag.byteValue();Please tell me why i get this error and help me solve it.
Thanks in advance

Is there any way to convert a long to a byte. willbyte b = (byte) 1234567890L;
byteValue() help?Depends on what you try to do do. Just how are you converting 1000L to one byte?
i have tried with it, but i get an
error saying "long cannot be dereferenced.
Please tell me why i get this error and help me solve
it.You get this error because you don't know the differences between long and Long, or primitive data types and objects.
new Long(myLong).byteValue()

Similar Messages

  • Need to convert a long into a string, please

    hi there
    i need to convert a long into a string. can i just cast it like this:
    (String)longNumber = some function that returns a long;

    Why not just use Long.toString()? If you start with a long value, you can create a Long object and get it's value as a String.

  • Is there an easy way to convert a long string into an array?

    I can convert a long string into a 1-d array by parsing and using build array, but I would like to know if there is a function to make this easier.
    For example:
    from/   aaaaaaaabbbbbbbbccccccccdddddddd         (string of ascii)
    to/       an array that is 1-d with each element having eight characters
              aaaaaaaa
              bbbbbbbb
              cccccccc
              dddddddd
    Thank you.
    Solved!
    Go to Solution.

    Try something like this:
    (If you can guarantee that the string length is an integer multiple of 8, you an drop the two triangular modes in the upper left. )
    Message Edited by altenbach on 03-14-2010 06:40 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ChopString.png ‏9 KB

  • How to convert an Image to a byte array?

    I want to make a screenshot and then convert the image to a byte of arrays so I can send it through a BufferedOutputStream.
    try
                   robot = new Robot();
                   screenshot = robot.createScreenCapture(new Rectangle(500,500));
                   imageFile = new File("image.png");
                   ImageInputStream iis = ImageIO.createImageInputStream(screenshot);
                   byte[] data = new byte[1024];
                   byte[] tmp = new byte[0];
                   byte[] myArrayImage = new byte[0];
                   int len = 0;
                   int total = 0;
                   while((len = iis.read(data)) != -1 ) // LINE 52 --- EXCEPTION CATCHED HERE
                        total += len;
                        tmp = myArrayImage;
                        myArrayImage = new byte[total];
                        System.arraycopy(tmp,0,myArrayImage,0,tmp.length);
                        System.arraycopy(data,0,myArrayImage,tmp.length,len);
                   ios.close();I get this exception while running:
    Exception in thread "Thread-0" java.lang.NullPointerException
    at Server.run(Server.java:52)
    at java.lang.Thread.run(Unknown Source)

    Fixed that. I got a new problem.
    When I connect to my simple server application that reads the image file, converts it to an array of bytes and sends it back, the file is created on the client side and it containts data, but I am not able to open the image. I have checked that the image that the server is sending is working. So where is the problem?
    The client application recieves the image as following:
    public void run()
            try
                socket = new Socket("127.0.0.1", 2000);
                BufferedOutputStream out_file = new BufferedOutputStream(new FileOutputStream("recieved_img.png"));
                BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                int inputLine;
                while((inputLine = in.read()) != -1)
                    char c = (char)inputLine;
                    System.out.println(c);
                    out_file.write(inputLine);
            catch(IOException err){ err.printStackTrace(); }
        }And the server sends the image like this;
    try
              socket = server.accept();
              in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
              out = new BufferedOutputStream(socket.getOutputStream());
              out.write(25);
              while((inputLine = in.readLine()) != null)
                   System.out.println(myArrayImage.length);
              System.out.println(inputLine);
                        out.write(myArrayImage);     // Send the array of bytes
         }

  • Code of a method longer than 65536 bytes

    I just moved my web application (jsp/servlets, no EJB) from apache tomcat to Oracle 9iAs Container for J2EE (OC4J). Everything is working fine except one jsp file, called "EditTmpForm.jsp". Basically, this jsp file is used to update existing records, so it needs to first retrieve the data from the database by using the primary keys. I used a java bean to handle the JDBC/SQL code and plugged that bean into the jsp file. The jsp works fine on tomcat, but when I run it on OC4J, I got the following error:
    500 Internal Server Error
    Error parsing JSP page /pirs/jsp/EditTmpForm.jsp
    Error creating jsp-page instance: java.lang.ClassFormatError: jspPage19jsp_EditTmpForm.jsp (code of a method longer than 65536 bytes)
    Why does it give me this error? 65536 bytes is only 64k, which can be stored in a floppy disk.
    Thank you very much if you can give me some idea why this occurs.
    James

    I looked at the code after a jsp compiled to a servlet. The
    jspService method of "EditTmpForm.jsp" is about 801 KB. But for another jsp "EditOperation.jsp", the  jspService method is about 236 KB.
    Both are much greater than 64 K, but why it runs okay for "EditOperation.jsp" but gives me error for "EditTmpForm.jsp"?
    Furthermore, since the HTML form is long, so the HTML code itself is bigger than 64 K, how can you prevent your _jspService method so that is is shorter than 64K?
    Thanks for your help!
    James

  • Text fields being converted to Long in Data Integrator v 11.7

    I am a new user to BODI, and I recently experienced an issue with source "TEXT" fields being converted to "LONG" in the Query and Target datastores respectively. I am using Data Integrator v 11.7 and my question is does anyone know whether or not this issue has been resolved in Data Services XI 3..x? if so, can you also provide documentation on this exact issue? Thanks in advance.
    Lonnie

    Yes, we did some changes in DI 12.0. But what is the problem? A SQL Server TEXT datatype is a text with unlimited length whereas a varchar(maxsize) is limited. In Oracle a CLOB is the same thing. And in DI we call a text of unlimited size a LONG datatype.

  • Error:Type mismatch: cannot convert from Long to Long

    hi friends,
    I've a problem.I've a JSP that does some long converions,and its working fine when i make it run on my machine i.e
    (Running Tomcat5.0),but when I deploy this file on the server which runs Tomcat 5.5.7,it throws this error:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 20 in the jsp file: /abc.jsp
    Generated servlet error:
    Type mismatch: cannot convert from Long to Long
    Can anyone of you,tell me where i am going wrong???

    Here is an example of doing it with a JavaBean... the bean looks like this:
    package net.thelukes.steven;
    import java.io.Serializable;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class FormHandlerBean implements Serializable {
         private static final long serialVersionUID = 1L;
         private Date startTime = null;
         private DateFormat dateFormatter;
         public FormHandlerBean() {
              setDateFormat("yyyy-MM-dd hh:mm:ss");
         public void setStart(String strt) {
              setStartAsString(strt);
         private void setStartAsString(String strt) {
              setStartAsDate(getDate(strt));
         private void setStartAsDate(Date d) {
              startTime = d;
         private Date getDate(String s) {
              Date d = null;
                   try {
                        d = dateFormatter.parse(s);
                   } catch (ParseException pe) {
                        System.err.print("Error Parsing Date for "+s);
                        System.err.println(".  Using default date (right now)");
                        pe.printStackTrace(System.err);
                        d = new Date();
              return d;
         public long getStartAsLong() {
              return getStart().getTime();
         public String getStartAsString() {
              return Long.toString(getStartAsLong());
         public Date getStart() {
              return startTime;
         public void setDateFormat(String format) {
              dateFormatter = new SimpleDateFormat(format);
    }You would only need to make the getStartXXX methods public that need to be accessed from the JSP. For example, if you will not need to get the Long value of the time, then you do not need to make getStartAsLong public...
    The JSP looks like this:
    <html>
      <head>
        <title>I got the Form</title>
      </head>
      <body>
        <h3>The Output</h3>
        <jsp:useBean class="net.thelukes.steven.FormHandlerBean" id="formHandler"/>
        <%
             formHandler.setStart(request.getParameter("start"));
        %>
        <table>
          <tr><td>Start as String</td><td><jsp:getProperty name="formHandler" property="startAsString"/></td></tr>
          <tr><td>Start as Date</td><td><jsp:getProperty name="formHandler" property="start"/></td></tr>
          <tr><td>Start as long</td><td><jsp:getProperty name="formHandler" property="startAsLong"/></td></tr>
        </table>
      </body>
    </html>If this were a servlet processing the form rather than a JSP, I might throw the ParseException that might occur in getDate and catch it in the Servlet, with which I could then forward back to the form telling the user they entered mis-formatted text value... But since JSPs should be mainly display, I catch the exception internally in the Bean and assign a safe value...

  • Convert LAT/LONG to X/Y

    Hello all,
    i've searched this forum to see how I can convert LAT/LONG values to XY coordinates.
    I've found this:
    SELECT
    sdo_geometry(2001, 8307, null, sdo_elem_info_array(1, 1003, 1),
    sdo_ordinate_array(52.849497, 5.723975, 52.883151, 5.999025))
    FROM DUAL
    I thought that when i executed this query, i'd see 2 values. But i was wrong.
    Is there a function that will return the XY when I give the LAT/LONG values ???

    You geometry does not validate (sdo_geom.validate_geometry(...) ,gtype and etype don't match!). You used a gtype 2001 (point) but in your elem_info_array (etype 1003) is an exterior polygonal ring. You need to fix your geometry first.
    When you said you want to converting lat/long to X/Y did you mean to convert a lat/long to a point (x,Y) in a projected coordinate system? If so, you can convert the geodetic geometry to a projected geometry(sdo_cs.transform), then use the SDO_UTIL.GETVERTICES function to retrieve all points in their order.
    From oracle spatial manual :
    SDO_CS.TRANSFORM(
    geom IN MDSYS.SDO_GEOMETRY,
    to_srid IN NUMBER
    ) RETURN MDSYS.SDO_GEOMETRY;
    SDO_UTIL.GETVERTICES
    Format
    SDO_UTIL.GETVERTICES(
    geometry IN SDO_GEOMETRY
    ) RETURN VERTEX_SET_TYPE;
    Description
    Returns the coordinates of the vertices of the input geometry.
    Parameters
    geometry
    Geometry for which to return the coordinates of the vertices.
    Usage Notes
    This function returns an object of VERTEX_SET_TYPE, which consists of a table of objects of VERTEX_TYPE. Oracle Spatial defines the type VERTEX_SET_TYPE as:
    CREATE TYPE vertex_set_type as TABLE OF vertex_type;
    Oracle Spatial defines the object type VERTEX_TYPE as:
    CREATE TYPE vertex_type AS OBJECT
    (x NUMBER,
    y NUMBER,
    z NUMBER,
    w NUMBER,
    id NUMBER);
    This function can be useful in finding a vertex that is causing a geometry to be invalid. For example, if you have identified a geometry as invalid by using the SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT function or the SDO_GEOM.VALIDATE_LAYER_WITH_CONTEXT procedure (both of which are documented in Chapter 15), you can use the GETVERTICES function to view the vertices in tabular format.
    Examples
    The following example returns the X and Y coordinates and ID values of the vertices of the geometries in the SHAPE column of the COLA_MARKETS table. (The example uses the definitions and data from Section 2.1.)
    SELECT c.mkt_id, c.name, t.X, t.Y, t.id
    FROM cola_markets c,
    TABLE(SDO_UTIL.GETVERTICES(c.shape)) t
    ORDER BY c.mkt_id, t.id;
    MKT_ID NAME X Y ID
    1 cola_a 1 1 1
    1 cola_a 5 7 2
    2 cola_b 5 1 1
    2 cola_b 8 1 2
    2 cola_b 8 6 3
    2 cola_b 5 7 4
    2 cola_b 5 1 5
    3 cola_c 3 3 1
    3 cola_c 6 3 2
    3 cola_c 6 5 3
    3 cola_c 4 5 4
    3 cola_c 3 3 5
    4 cola_d 8 7 1
    4 cola_d 10 9 2
    4 cola_d 8 11 3
    15 rows selected.

  • Limitation of converting from Long Raw to Blob

    Hi All,
    DB:11g
    Oracle Apps:R12
    Is there a limitation of converting from Long Raw to Blob?
    Please share your experience on this subject in case anyone has faced it before.
    Thanks for your time!
    Regards,

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:13213885403654
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:510622111991

  • Converting a long to a string  (PLEASE HELP)

    I am trying to convert a long to a string so that I can put it into a vector. I have this:
    long fileSize = 0;
    String fileModDate = null;
    Vector fileList = new Vector();
         ~~~~~~~
    File [] files = myDir.listFiles();
    for (int i = 0; i<files.length; i++){
    fileSize = files.length();
    String s = fileSize.toString();
    //do the same for the mod date
    fileModDate = files[i].lastModified();
    When i try this, i get an error that long can not be dereferenced. Can anyone please help?

    There are two ways to solve this problem. You are trying to convert a primative type to a string without using its wrapper function (Long). So if you created a long variable as a (Long) object you could call its toString() method and this would work...
    The other way is to simply use the static method in the String class valueOf(long) as follows:
    String longString = String.valueOf(i);Hope this helps.
    Mark

  • Converting unsigned to java signed byte value

    Hey ,
    i need to use a raw address in a client i am writing but, of course, the address contains a byte outside of the java signed byte range. if any one could tell me what an unsigned byte of 224 in signed java is i would be very grateful, if you could also show how you did this it would be appreciated. thank you =)

    Re: Converting unsigned to java signed byte value
    i need to use a raw address in a client i am writing
    but, of course, the address contains a byte outside
    of the java signed byte range.
    if any one could tell
    me what an unsigned byte of 224 is in signed java
    I would be very grateful, if you could also show how
    you did this it would be appreciated. thank you =)You misunderstand signed/unsigned.
    A byte has 8 bits. It can represent 256 different values.
    Viewed as an unsigned scalar the range is [0;255].
    Viewed as a signed two's-complement scalar the range is [-128;127].
    Values [0;127] are obviously the same byte values in the two views.
    What the other half of the possible byte values represent depends on what view you adopt.
    You don't need to convert anything.
    public final class Byte224 {
        static byte[] byteArray = {
            (byte)224, (byte)'\n'
        public static final void main(final String[] arg) {
            System.out.println("0x"+Integer.toHexString(byteArray[0]&0xff));
            System.out.println(Integer.toString(byteArray[0]&0xff));
    }

  • Code of a method longer than 65535 bytes...

    I am working with Tomcat32. I made a taglibrary(that includes just one tag, for testing) and implemented the tag in java (a simple one, it's just writing a text). I put that tag into a JSP page and when I go to that page, the tag displays a text on the screen. Everything works just fine, but if I have a greater number of tags inside the JSP(about 170), then I get an error message. Tomcat makes the .java -file, compiles it to the .class file, and then just before displaying the text, I get the following err.msg: "Code of a method longer than 65535 bytes..." Thanks for any help I get ! Bye, Nico

    The code of a method cannot longer than 65535 bytes, but note that in
    http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
    the attribute length field is specified as four bytes:
    u4 attribute_length;
    You can demonstrate this for yourself with a program I recently posted here
    http://forum.java.sun.com/thread.jspa?threadID=603213
    by changing the num_calls from 5000 to 50000 .
    The error will look like:
    Exception in thread "main" java.lang.ClassFormatError: a1000000000 (Code of a me
    thod longer than 65535 bytes)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
    at maxperm_cltest$MyLoader.doClass(maxperm_cltest.java:303)
    at maxperm_cltest.main(maxperm_cltest.java:282)
    I note that repeatedly calling a no-arg void method is only four bytes per call. Your example, compiled by Sun's javac, would only consume about 50 bytes for the code and 100 bytes in the class file overall.

  • How to convert a Long data to Date format in LabVIEW 7.0

    I am using a ehternet communication between TINI and Labview. From TINI I am throwing Temperature( DOUBLE) and Date and time Information(LONG). When I try to catch it via TCP/IP client in LabVIEW(Simple Data Server Example) it in fact show me the Temperature value which get converted via Type cast. But the Date information I have tried with time stamp and others but it is not getting solved. I am not getting the right time/date information at all. when I connect it to time stamp it shows me some 1904 and some other time. I dun know why it is happening . any one can help. I am really stuck in here.

    Dear James
    Thank for your reply. I have tried with byte changing and it is not working. when I set it to 8 in timestamp nothing shows and I tried them changing the byte range and it not showing the proper result. I also believe that I have problem in the java code i am sending. how ever I have send the whole application I am working on.
    You will see in "HumiditySample.java"; long timeStamp is taking time from system which is written on dout.writeLong in "HumidityLogger.java" which is now captured by "loggingdaemon.java" which finally throws the data in "datalogger.java"to write on the network connection. There is a java file
    called"DataLoggerClient.java" which can be run to see the
    readings file correctly from the machine which in fact read corriectly as a Client while labView I am facing the problem. Hope this information will help u to get the problem. I am consistengly tring to solve it but i am stuck here. I am tring to learn. please help me out.
    regards
    shawon
    London Metropolitan University
    Attachments:
    shawonjava.zip.zip ‏16 KB
    shawonclient-mod.vi ‏75 KB

  • How can I convert an Hexadecimal number in bytes

    Hello!
    I have a string wich represents an hexadecimal value ( ex: C2105215767E)
    I want to convert it into byte. I want to obtain an array of byte. I want to write it into a variable : byte[]var
    How can I do it?
    Thanks you for your answer.
    cordialy,
    lafon1

    Look into the API for BigInteger. You can use a constructor that takes a String and specify the radix as 16 (hex). Big Integer includes a method to convert to a byte array.

  • Trying to understand the details of converting an int to a byte[] and back

    I found the following code to convert ints into bytes and wanted to understand it better:
    public static final byte[] intToByteArray(int value) {
    return new byte[]{
    (byte)(value >>> 24), (byte)(value >> 16 & 0xff), (byte)(value >> 8 & 0xff), (byte)(value & 0xff) };
    }I understand that an int requires 4 bytes and that each byte allows for a power of 8. But, sadly, I can't figure out how to directly translate the code above? Can someone recommend a site that explains the following:
    1. >>> and >>
    2. Oxff.
    3. Masks vs. casts.
    thanks so much.

    By the way, people often introduce this redundancy (as in your example above):
    (byte)(i >> 8 & 0xFF)When this suffices:
    (byte)(i >> 8)Since by [JLS 5.1.3|http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#25363] :
    A narrowing conversion of a signed integer to an integral type T simply discards all but the n lowest order bits, where n is the number of bits used to represent type T.Casting to a byte is merely keeping only the lower order 8 bits, and (anything & 0xFF) is simply clearing all but the lower order 8 bits. So it's redundant. Or I could just show you the more simple proof: try absolutely every value of int as an input and see if they ever differ:
       public static void main(String[] args) {
          for ( int i = Integer.MIN_VALUE;; i++ ) {
             if ( i % 100000000 == 0 ) {
                //report progress
                System.out.println("i=" + i);
             if ( (byte)(i >> 8 & 0xff) != (byte)(i >> 8) ) {
                System.out.println("ANOMOLY: " + i);
             if ( i == Integer.MAX_VALUE ) {
                break;
       }Needless to say, they don't ever differ. Where masking does matter is when you're widening (say from a byte to an int):
       public static void main(String[] args) {
          byte b = -1;
          int i = b;
          int j = b & 0xFF;
          System.out.println("i: " + i + " j: " + j);
       }That's because bytes are signed, and when you widen a signed negative integer to a wider integer, you get 1s in the higher bits, not 0s due to sign-extension. See [http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.2]
    Edited by: endasil on 3-Dec-2009 4:53 PM

Maybe you are looking for

  • Auto batches in case of backflush

    Hi MM gurus, Pl.tell me why i am not getting batches in CO11N IN prodn.. Actually component require 30 qty. and i have 3 batches of 10 nos.but it is not coming automatically in goods movement screen in co11n. I already maintained in OPJ2 stock and ba

  • I used to be able to skip a cell to the right by using the toggle arrow keys

    I placing a number or text in a cell i used to be able to skip the cell to the right by using the toggle arrow keys.  I can't now?  Using the RETURN key only goes down a cell.  I want to go right?  Why?

  • How to install developer suite on windows vista

    trying to install the dveloper suite on windows vista, keep gettting error that the pagefile(swap file) size is 0 and need to fix this problem. did any one have this problem using developer suite x86-101202 (compatibility mode xp sp2)

  • SAP XI Acknowledgements in asynchronous communication without using BPM.

    Hello experts, My scenario is File (Legacy system) -> XI->IDOC & I need to send the acknowledgement back to legacy system. How SAP XI acknowledgements work in asynchronous scenarios without a BPM process. I know it has to do something with ALEAUDIT.

  • MAXL Errors in a Working Script

    Hi All,Making the transistion to MAXL from ESSCMD under Essbase 6.2. I have a script that successfully builds two of my dimensions using the SQL interface from Oracle. What's strange is, even though the script works, mid-way through MAXL log file, th