Putting integer value of 163 into byte array

I have an integer value of 163. I need to put that into a byte array. When i do, it puts it as -93. Whats wrong? and how can i put it in correctly?

Hi,
You cannot store 163 in a byte variable. In Java a byte variable will have only 8 bits and its value range will be from -128 to +127. In a byte variable you cannot store a value which is out of this range. If you try to cast an integer value which is out of this range to byte then you will get unexpected results (But you can find what the result will be).

Similar Messages

  • How to put 58 columns of data into an array in one shot?

    I have a set of data with 58 columns and 5000 rows. However, I need to find offset for all the elements in this 5000x58 set of data. Is there an easier way to put all the data (offset) into an array in one shot other than using build array function? This is because if I use the build array function, I will need to separate all the data into 58 columns by indexing them. This is too time consuming.
    Thanks for the suggestion! Have a good day!

    VanessaWen wrote:
    I have a set of data with 58 columns and 5000 rows. However, I need to find offset for all the elements in this 5000x58 set of data. Is there an easier way to put all the data (offset) into an array in one shot other than using build array function? This is because if I use the build array function, I will need to separate all the data into 58 columns by indexing them. This is too time consuming.
    You need to explain in much more detail, because your problem is not clear.
    Is this a 2D array with 58 columns and 5000 rows?
    What is your definition of "offset"?
    Where does the offset value come from?
    Is "offset" it the same for each row (or column) or does it depend on the data?
    What is the definition of "one shot"?
    Why would you need to seperate all the data into columns in order to use build array?
    It it "too time consuming" to write the program or is the execution slower than expected?
    Is the final output a 1D or 2D array or something else?
    Please attach a VI containing a small 2D array diagram constant with typical data, then show us what kind of output you would expect after applying the described operation.
    LabVIEW Champion . Do more with less code and in less time .

  • Converting image into byte array

    Hi all,
    How to convert an integer array image into byte array ?
    here i have a image like this :
    private static int pixelArray[] = {
    0xff000000, 0xff000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0xff000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
    From this one i create image like this one :
    Image image = Image.createRGBImage(pixelArray, width, height, true);
    Now i want to convert that pixelArray into byte array ? how to do this
    additionally i want to send this byte array to servlet .
    thanks in advance.

    Hi,
    If you want to convert your int array to a byte array you should
    split each integer into 4 bytes to avoid losing information. You can
    rebuild your integer array later if you need to. I think this code
    will work (i havent tested it):
    byte[] pixel= new byte[pixelArray.length<< 2];
    for (int i= pixelArray.length- 1; i>= 0; i--) {
      int aux= i<< 2;  // i* 4 = i<< 2
      pixel[aux]=    (byte) (pixelArray>> 32);
    pixel[aux+ 1]= (byte) (pixelArray[i]>>> 16);
    pixel[aux+ 2]= (byte) (pixelArray[i]>>> 8);
    pixel[aux+ 3]= (byte) pixelArray[i];
    Greets.

  • What is the best way to convert a cluster into byte array or string

    I'm writing a program that sends UDP packets and I've defined the data I want to send via large clusters (with u8/u16/u32 numbers, u8/u16/u32 arrays, and nested clusters). Right before sending the data, I need to convert the clusters either into strings or byte arrays. The flatten to string function is almost perfect for this purpose. However, it's appending lengths to arrays and strings which renders this method useless, as far as I can tell. 
    As I have many of these clusters, I would rather not hard code the unbundle by names and converting/typecasting to byte arrays or strings for each one. 
    Is there a feature or tool I am overlooking? 
    Thank you! 

    deceased wrote:
    Flatten to string has a boolean input of "Prepend string or array size" ... The default value is true.
    That only specifies if a string or array size should be prepended if the outermost data element is a string or array. For embedded strings or arrays it has no influence. This is needed for the Unflatten to be able to reconstruct the size of the embedded strings and arrays.
    The choice to represent the "Strings" (and Arrays) in the external protocol to LabVIEW strings (and arrays) is actually a pretty bad one unless there is some other element in the cluster that does define the length of the string. An external protocol always needs some means to determine how long the embedded string or array would be in order to decode the subsequent elements that follow correctly.
    Possible choices here are therefore:
    1) some explicit length in the protocol (usually prepended to the actual string or array)
    2) a terminating NULL character for strings, (not very friendly for reliable protocol parsing)
    3) A fixed size array or string
    For number 1) and 2) you would always need to do some special processing unless the protocol happens to use explicitedly 32 bit integer length indicators directly prepended before the variable sized that.
    For number 3) the best representation in LabVIEW is actually a cluster with as many elements inside as the fixed size.
     

  • How do I read directly from file into byte array

    I am reading an image from a file into a BuffertedImage then writing it out again into an array of bytes which I store and use later on in the program. Currently Im doing this in two stages is there a way to do it it one go to speed things up.
    try
                //Read File Contents into a Buffered Image
                /** BUG 4705399: There was a problem with some jpegs taking ages to load turns out to be
                 * (at least partially) a problem with non-standard colour models, which is why we set the
                 * destination colour model. The side effect should be standard colour model in subsequent reading.
                BufferedImage bi = null;
                ImageReader ir = null;
                ImageInputStream stream =  ImageIO.createImageInputStream(new File(path));
                final Iterator i = ImageIO.getImageReaders(stream);
                if (i.hasNext())
                    ir = (ImageReader) i.next();
                    ir.setInput(stream);
                    ImageReadParam param = ir.getDefaultReadParam();
                    ImageTypeSpecifier typeToUse = null;
                    for (Iterator i2 = ir.getImageTypes(0); i2.hasNext();)
                        ImageTypeSpecifier type = (ImageTypeSpecifier) i2.next();
                        if (type.getColorModel().getColorSpace().isCS_sRGB())
                            typeToUse = type;
                    if (typeToUse != null)
                        param.setDestinationType(typeToUse);
                    bi = ir.read(0, param);
                    //ir.dispose(); seem to reference this in write
                    //stream.close();
                //Write Buffered Image to Byte ArrayOutput Stream
                if (bi != null)
                    //Convert to byte array
                    final ByteArrayOutputStream output = new ByteArrayOutputStream();
                    //Try and find corresponding writer for reader but if not possible
                    //we use JPG (which is always installed) instead.
                    final ImageWriter iw = ImageIO.getImageWriter(ir);
                    if (iw != null)
                        if (ImageIO.write(bi, ir.getFormatName(), new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Unable to Write Image");
                    else
                        if (ImageIO.write(bi, "JPG", new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Warning Unable to Write Image as JPEG");
                    //Add to image list
                    final byte[] imageData = output.toByteArray();
                    Images.addImage(imageData);
                  

    If you don't need to manipulate the image in any way I would suggest you just read the image file directly into a byte array (without ImageReader) and then create the BufferedImage from that byte array.

  • Class Object into Byte Array

    Is there a way to copy a class object into a byte array? If so, how?

    hi check out
    http://forum.java.sun.com/thread.jspa?threadID=562268&
    messageID=2766098This does not work in j2me. WriteObject does not exist, and there are no serialsation interfaces in j2me. So you'll have to do that on your own.
    look here: http://java.sun.com/developer/J2METechTips/2002/tt0226.html

  • How do I put and sort string data into an array?

    I have a txt file that has the following sample data:
    Sample.txt----
    Jones Bill 12,500 Salesperson
    Adams Frank 34,980 Manager
    Adams John 23,000 Salesperson
    Thompson Joe 59,500 Trainee
    I need to incorporate each line of data into an individual array element, while using a user-defined method
    (ex. setAllValues(String last, String first, String salary, String job)
    How do I loop the data into the array to be displayed and what is the best way to do sorts on this sample data. Any code or clues would be super helpful.
    Sanctos

    If you set up an array of Strings you can use the java.util.Arrays.sort() method to sort it. If you need to sort arbitrary Objects (i.e. your 3 strings as a whole entity) your 3-way object will have to either implement Comparable or you could write a Comparitor class to do the ordering. Not much to it, though.
    Dom.

  • Conversion of image into byte array

    I have a problem in converting .png image into bytestream, if anyone can help in this pls do so.....

    Hi,
    To convert an Image to bytes you can use the Image.getRGB() method.
    http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Image.html#getRGB(int[], int, int, int, int, int, int)
    -Henrik

  • Reading a pdf file from URL into Byte array/ByteBuffer in an applet.

    I'm trying to figure out why this particular snippet of code isn't working for me. I've got an applet which is supposed to read a .pdf and display it with a pdf-renderer library, but for some reason when I read in the .pdf files which sit on my server, they end up as being corrupt. I've tested it by writing the files back out again.
    I've tried viewing the applet in both IE and Firefox and the corrupt files occur. Funny thing is, when I trying viewing the applet in Safari (for Windows), the file is actually fine! I understand the JVM might be different, but I am still lost. I've compiled in Java 1.5. JVMs are 1.6. The snippet which reads the file is below.
    public static ByteBuffer getAsByteArray(URL url) throws IOException {
            ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
            URLConnection connection = url.openConnection();
            int contentLength = connection.getContentLength();
            InputStream in = url.openStream();
            byte[] buf = new byte[512];
            int len;
            while (true) {
                len = in.read(buf);
                if (len == -1) {
                    break;
                tmpOut.write(buf, 0, len);
            tmpOut.close();
            ByteBuffer bb = ByteBuffer.wrap(tmpOut.toByteArray(), 0,
                                            tmpOut.size());
            //Lines below used to test if file is corrupt
            //FileOutputStream fos = new FileOutputStream("C:\\abc.pdf");
            //fos.write(tmpOut.toByteArray());
            return bb;
    }I must be missing something, and I've been banging my head trying to figure it out. Any help is greatly appreciated. Thanks.

    Keshav.. wrote:
    I too was going through the same problem but I found for some pdfs it worked fine.I didnt get ur solution.Please explain bcoz it may work for every pdfThis thread is over 3 years old and dead. Please open a new thread which provides details of the problem you are having. Link to this thread if you think it is necessary.
    I shall lock this thread.

  • Putting calculated value into another application

    Hi,
    I have an HCM application with the following simple HRAccount dimension.
    ALL_HR_ACC
         |___SALARY
         |___BONUS
         |___OT
    I want to put the value of ALL_HR_ACC into TstAccount.HRExp, which is in another application called TstFinance. This can be perfectly done by the following code.
    *DESTINATION_APP=TstFinance
    *SKIPDIM=Employee
    *RENAME_DIM HRAccount=TstAccount
    *WHEN HRAccount
       *IS SALARY,BONUS,OT
           *REC(FACTOR=1,HRAccount="HRExp")
    *ENDWHEN
    However, if I change the IS statement to the following, nothing will happen.
       *IS ALL_HR_ACC
    In this simple example, I don't mind putting all 3 HR accounts SALARY,BONUS,OT. However, in many situations, SALARY and other HR accounts are derived from other accounts as well. It could be very cumbersome to put the whole bunch of calculation into the script for just transferring the single value of ALL_HR_ACC into another application.
    Anyone could give me any advice on this? Somebody told me using EVGTS could easily do the trick. However, such functions or formulas will disappear when I expand the worksheet.
    Thank you!
    Sunny

    Sunny,
    The script behavior is correct.  Script logic basically only works with the base memebrs, unless you utilize the statement called Calc Dummy Org.  This statement acts like a variable and aggregates the values into a "parent" type value to be passed on or used in a REC statement.  But, the process you used for the purpose you have is the best, fastest method, even if it is a scope of 50 base accounts from a select statement.
    As for using an input template or excel; if you have an evdre expansion input template, and wish to send the values to a different cube, just add another EVDRE, but remove all the expansions.  Make the page key range fixed or based on the other EVDRE statement.  Use excel to relate to the account to be sent  to the parent account. It should be quite simple to send the total values to a summary cube from the same template that is used for the input process.  However, the logic you wrote accomplished the same effect.
    Hope this helps.

  • How to read an inputStream in UTF-8 into a byte array.

    Hi, Java version is 1.4.2. If inputStream.read() is used to read the bytes into a byte array, is it guarenteed that UTF-8 chars are correctly transferred into byte array? Or should we use InputStreamReader? An example would be a great help.
    Thanks in advance.

    I would like to send a byte array read from InputStream to another app where they are converted to UTF-8. In brief
    -Read input stream which comes in UTF-8 into a byte array
    -Send byte array to another app which will convert it into UTF-8 characters

  • How to change the image into byte and byte array into image

    now i am developing one project. i want change the image into byte array and then byte array into image.

    FileInputStream is = new FileInputStream(file);
    byte[] result = IOUtils.toByteArray(is);
    with apache common IO lib

  • JVM error while reserving big byte array

    Hi all, I've encountered a strange problem while trying to unzip a big file (~100MB):
    I have to work with it in memory so I load it into byte array - this never caused any troubles until I tried to unpack a file of such big size - more detailed investigation showed that just a line like that:
    byte[] bb = new byte[100000000] - ruins a service thread WITHOUT giving an exception (so that, try-catch around it don't react on it)!
    The system config is here:
    P4 1.4GHz, 512 RAM, JDK1.5.u6
    Anyone saw such trouble?

    What was the specific error message or symptom you saw?
    Also please include which version of java you are using (the output
    from java -version).

  • Bytes array to double words array

    I have an array of bytes. I need to take 4 bytes at a time to create a doubleword (32bits).
    I am currently using Decimate Array and Join Numbers twice to do this.
    Is there a more efficient way of doing this that I am overlooking?
    Solved!
    Go to Solution.

    nyc wrote: I do have to perform endian manipulation. The information is little endian. My original information is a string from a TCPIP read. My current attempt is to convert it to a bytes array. 
    Can you explain in more detail what I would do in this case?
    As I noted, you can use the Unflatten From String. Since the data is coming from a TCP Read you can wire that directly to it:
    Message Edited by smercurio_fc on 06-15-2010 09:19 AM
    Attachments:
    byte array to integer array_BD.png ‏8 KB
    byte array to integer array.vi ‏18 KB

  • Is there a null value that I can put into a byte array?

    I have a byte[] that I'm trying to make smaller, at the moment, in order to do so, i'm writing it byte-by-byte to another byte[] called temp. Both are set to the same size, because I don't know exactly what the initial array will compress to.
    For example, my method will write a single byte that will tell the decompressor to carry out the next instruction 5 times (eg aaaaa = 5a), but after the instruction, I want to set the 4 a's afterwards to an empty value so that I can then iterate through temp, finding out how long to make the output byte[] by counting how many null's there are.
    Eclipse is telling me null is not possible to use, I was just wondering if there is an equivalent I can use?

    That's an idea!
    The only thing is then when I come to iterate through the byte array to write it to my output array, it throws up an error that I'm trying to compare a byte to a byte[]:
              int next = 0;
              byte[] n = new byte[0];
              for (int i = 0; i < temp.length; i++) {
                   if (temp[i] != n) {
                        output[next] = temp;
                        next++;
              return output;

Maybe you are looking for