Dividing a short value up to two byte values

Hi!
I have small problem converting data between two types. I have a short value and want to divide it tto two bytes instead. For example if I have th short value 3096 (1100000110000000, little endian) I want to split that value into two bytes, byteHigh and byteLow. These bytes should afterwards contain :
byteLow = 11000001
byteHigh = 10000000.
Can someone help me how to perform this casting? I will use it when handling real time audio so I prefer the solution to have good performance :)
regards,
Andreas

: you are shifting the sign with >>public class Split{
     public static void main(String[] args ){
          short s = (short) 0xC180; // 1100 0001 1000 0000
          int lower = (int) (s & 0x00FF);
          int upper = (int) ((s >>> 8) & 0x00FF);
          System.out.println("Upper: " +Integer.toHexString(upper));
          System.out.println("Lower: " + Integer.toHexString(lower));

Similar Messages

  • How to cram two bytes into a short?

    Hi all,
    I have some byte[] data that I am receiving, and I need to put two bytes into one short (or int, or whatever), as the byte[] will form a two bytes-per-pixel image. I've been working with 8-bit data (this is 12-bits, NOT packed), which is much easier to manipulate.
    I currently have this method to convert a byte[] of 8-bit data into a short (I do this because Java does not support signed types and I need that 8th bit):
    private short[] convertBytesToShorts(byte[] data) {
         short[] convertedData = new short[data.length];
         for (int i = 0; i < data.length; i++) {
              convertedData[i] = (short)((short)data[i] & 0xff);
         return convertedData;
    }Is there a way to modify this to place two bytes into one short? Is it possible to just AND two bytes with 0xff and add them together to create one short? Surely it cannot be that simple. Also, remember that I must treat the values as unsigned.
    Furthermore, the two bytes look like this:
    | xxxx xxxx | xxxx 0000 |So the last four bits in the second byte are 0s.
    Any advice is appreciated.
    Message was edited by:
    Djaunl

    I've been working with 8-bit
    data (this is 12-bits, NOT packed), Obviously that is contradictory.
    I currently have this method to convert a byte[] of
    8-bit data into a short (I do this because Java does
    not support signed types and I need that 8th bit):
    Yes it does. The fact that it displays a byte as and integer and the conversion in that process produces a negative display value has nothing at all to do with the bits.
    Is there a way to modify this to place two bytes into
    one short? short s = (short)(((b1 << 8) & 0x0ff) | (b2 & 0x0ff))
    Of course you still have to deal with getting the order correct.
    (You can probably get rid of that first mask but you would need to test that.)

  • Retrive two byte string from indesign document

    Hello All ,
    I want to retrive two byte character string from indesign document.
    The way I use to retrive text from indesign I get it in WideString format which is 32 bit value.
    When I convert WideString to PMString I get string which represent characters
    eg. if WideString is E20F then
    PMString to GetCString is 45323046 //represent character position
    I want to put logic to left shift E with 4 and , OR next byte 2
    i.e E<<4 => E0 | 2 => E2 .
    But not able to retrive value of char as E but I get it as 45 which is character position in font.
    I want char *str should contained 1 byte->E2 and 2 byte->0F
    I want to convert WideString to 2 byte string , Please give solution.
    Regards,
    Pallavi.

    Hello T Schneider ,
    Thanks for Reply.
    using below code I am able to get Widestring in uchar16 * format.
    WideStringConstUTF32Iter iter = wsText.begin();
    WideStringConstUTF32Iter last = wsText.end();
    uchar16 * wstwobyte = (uchar16 *)malloc(sizeof(uchar16)* wstringlen);
    int k =0;
    while(iter != last)
    * wstwobyte = *iter;
    iter++;k++; wstwobyte++;
    *wstwobyte = (uchar16 )'\0';
    But how to end the uchar16 string, and iterate it again.
    I want to pass this string to a function having datatype for input string as usigned short * .

  • How to deal with the two bytes character in 'IF_IXML_NODE'

    we can create dom with Xstring
    ostream = streamfactory->create_ostream_xstring( string = lv_xstring )
    but if one value of the node is two bytes character.
    if_ixml_node->get_value( ), only retrun string value, so the result is
    wrong, it will display "##", how to fix it?
    Thanks a lot for your help.

    we can create dom with Xstring
    ostream = streamfactory->create_ostream_xstring( string = lv_xstring )
    but if one value of the node is two bytes character.
    if_ixml_node->get_value( ), only retrun string value, so the result is
    wrong, it will display "##", how to fix it?
    Thanks a lot for your help.

  • Converting int type into two bytes!

    Hi everyone,
    i need help in converting types.
    I have and int ranging from 0-4095 that i would like
    to write in a file as couple of bytes.
    For example suppose the int has four bytes
    [A][C][D]
    i would like to write in a file only the two bytes [C][D].
    How can i do?
    What does the byte casting do?
    int number = 1000;
    (byte)number = ??
    Thank you in advance
    -- Andy

    someting like this:
    int data;
    byte byte0=(byte)((data&0x000000ff)>>0);
    byte byte1=(byte)((data&0x0000ff00)>>8);
    byte byte2=(byte)((data&0x00ff0000)>>16);
    byte byte3=(byte)((data&0xff000000)>>24);

  • I would like to remove a short gray edge from two images. I need help in that I am not yet able to use PhotoShop. Could somebody kindly help me with this?

    I would like to remove a short gray edge from two images. I need help in that I am not yet able to use PhotoShop. Could somebody kindly help me with this?

    I doubt it Doc Maik, but I am certainly happy to learn The image is this one (and a similar one). They would be beautiful portraits if not for the "extra mouth". The grey edge that I would like to remove is the excess of (grey) mouth that is actually my horse's chin, but that in the pictures looks like a wider, looping mouth. Practically, looking at the picture, the "extra mouth" to the left. What I would love it to be able correct that to look like a normal mouth, which means that half of the protruding edge should be removed. I am not sure I was able to explain myself, but here is one of the two pictures. I thank you for you kindness in being available to advise me.

  • I cant add two byte variable

    I want to add two byte variable and store result in a byte variable but there is an error. Pls clarify me.

    And the error is? The first error is
    A.java:1: 'class' or 'interface' expected
    Class AAnd since I believe that that is caused by the OP hurriedly retyping code rather than pasting his real code I am not wanting to waste time guessing what the real problem is.

  • I would like to ask about imovie. my project cannot output and how can i divide my project in imovie into two part??, i would like to ask about imovie. my project cannot output and how can i divide my project in imovie into two part??

    i would like to ask about imovie. my project cannot output and how can i divide my project in imovie into two part??, i would like to ask about imovie. my project cannot output and how can i divide my project in imovie into two part??

    Go to the Project Library View and select your project.
    Then FILE/DUPLICATE PROJECT and give the duplicate a name like "your name - part 1".
    Then duplicate it again and give the duplicate a name like "your name - part 2"
    Now you can open "part 1" as a project and delete everything that is in part 2.
    Open "part 2" as a project and delete everything that is in part 1.

  • DIVIDE BY ZERO VALUES NOT TO BE DISPLAYED IN QUERY

    Hi Friends,
                        How to make "divide by zero values" not to be displayed?
    Waiting for your input's
    Regards,
    Pattnaik...

    If you mean removung the Red Xs than:
    In order to remove the red Xs from the report (for example when dividing a number by zero), you can go to transaction RSCUSTV4 and change the definition from X to '  ' (Space). It might require creating a request but that's it.
    Hope it was helpful..
    Yaniv.

  • How to show Chinese (two-byte) in Creative MediaSou

    Need Help:
    I got buch Chinese mp3 with chinese characters as file name/track name. Creative MediaSource 2.03.29 will not show Chinese characters, only codes. I was forced to use MS media player, which shown proper characters.
    Anyone got idea how to get it works with two bytes chinese big-5 code?
    Thanks:-)
    Joseph

    HomeAustin,
    Change your Regional langauge setting in Control Panel to support Chinese PRC. That should have MediaSource displaying the lanaguage.
    Jason

  • Peek the first two bytes from socket

    I have a socket connection, using DataInputStream to read the bytes. However, I don't want to modify the input stream, by reading the first two bytes. I only want to peek the first two bytes without modifing the input stream. How can I do that?

    Instead of reading directly from the InputStream returned by the socket, go through a BufferInputStream:
    InputStream in = new BufferedInputStream(sock.getInputStream());
    in.mark(2);  // allow a reset until at most two bytes have been read
    in.read(); // read at most two bytes
    in.read();
    in.reset();  // reset the stream to the state prior to the two reads

  • Unable to merge two byte arrays

    Hi there,
    I am trying to merge two byte arrays into one byte array
    and write into a new word document using OutputStream object.
    But in the new word document that is created only the contents
    of the first byte array are being shown and not that of the second one.
    I have pasted the code below.
    Any pointers will be of great help.
    Thanks and Regards,
    Partha.
    package com.cisco.asit.icn.common.servlets;
    import java.io.ByteArrayInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import org.apache.poi.hwpf.HWPFDocument;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
    public class TestPOC {
         public static void main(String[] args) {
              try
                   System.out.println("I am here...");
                   System.out.println("I am in example 4...");
                   byte[] byteAr1 = getBytesFromFile(new File("c:\\Testing_POC\\Not_blank.doc"));
                   System.out.println(byteAr1.toString());
                   System.out.println();
                   byte[] byteAr2 = getBytesFromFile(new File("c:\\Testing_POC\\Quest.doc"));
                   byte[] finalOne = concatenate(byteAr1, byteAr2);
                   System.out.println("byte array 1..."+ byteAr1.length);
                   System.out.println("byte array 2..."+ byteAr2.length);
                   System.out.println("Final byte array ..."+ finalOne.length);
                   InputStream is = new ByteArrayInputStream(finalOne);
                   POIFSFileSystem fss = new POIFSFileSystem(is);
                   OutputStream out1 = new FileOutputStream("c:\\Testing_POC\\Result.doc");
                   fss.writeFilesystem(out1);
                   System.out.println("Stored to file system...");
                   try {
                        Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL \"" + "c:\\Testing_POC\\Result.doc");
                   catch (IOException e1){
                        e1.printStackTrace();
                   System.out.println("I am fine till here...");
         out1.flush();
         out1.close();
         catch (Throwable t) {
         t.printStackTrace();
         byte[] res = new byte[l.length + r.length];
         System.arraycopy(l, 0, res, 0, l.length);
         System.arraycopy(r, 0, res, l.length ,r.length);
    return res;
         public static byte[] getBytesFromFile(File file) throws IOException {
    InputStream is = new FileInputStream(file);
    // Get the size of the file
    long length = file.length();
    // You cannot create an array using a long type.
    // It needs to be an int type.
    // Before converting to an int type, check
    // to ensure that file is not larger than Integer.MAX_VALUE.
    if (length > Integer.MAX_VALUE) {
    // File is too large
    // Create the byte array to hold the data
    byte[] bytes = new byte[(int)length];
    // Read in the bytes
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length
    && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
    offset += numRead;
    // Close the input stream and return bytes
    is.close();
    return bytes;
    }

    parthInfy wrote:
    Hi there,
    I am trying to merge two byte arrays into one byte array
    and write into a new word document using OutputStream object.
    But in the new word document that is created only the contents
    of the first byte array are being shown and not that of the second one.
    Because the end of the first byte array contains a "document ending" tag and anything after that is just flotsam. And, even if you could remove that "document ending" tag, there is for the second a "document begin" tag. (Among many other tags and flags in both documents.) Word (ar just about any) documents are not simple text files to be concatented, truncated, twisted, inverted, or whatever else, at your pleasure. You actually, God forbid, have to kinow what you're doing, to manipulate them at this level. And, surprise, surprise, you don't.
    Edit: Google "POI"

  • ASCII to two bytes character

    How can I convert ASCII to two bytes character?
    such as 0 (ASCII) ----> 0 ( Two Bytes)
    Also, space (ASCII) ---> space(two bytes)
    Let me know... Thanks -

    Actually, that just constructs a new String by decoding the specified array of bytes using the platform's default charset (which may not be US-ASCII).
    A better way to do this is something like this:byte[] asciiContents = new byte[] {65, 83, 67, 73, 73}; // some bytes representing ASCII encoded characters.
    ByteBuffer inputBuf = ByteBuffer.wrap(asciiContents);
    Charset asciiCharset = Charset.forName("US-ASCII");
    CharBuffer outputBuf = asciiCharset.decode(inputBuf);
    System.out.println(outputBuf.toString());

  • Converting Japanese two Byte Character...

    Hi,
    I am doing a Scenario outbound from R/3.
    I am triggering the message via proxy using japanese language and sending to XI.
    In XI, we are getting the Mapping Error.
    Some records in the message contains single byte characters and some records having double byte characters.
    For single byte characters, XI is able to generate the target structure in the Mapping. But it is not able to convert the double byte characters to the target structure.
    Can any one help me to resolve this issue....
    Thanks in advance...
    Regards,
    Vasu

    Hi,
    Japanese data are Shift JIS encoded ? Maybe changing the encoding (or encoding declaration) could help ?
    Chris

  • How to calculate "if Y divided 0 then value=1" ?

    Hello,
    The usual formula is for NDIV0 is NDIV0(y/z) = 0 if b=0, otherwise y/z.
    I am looking for a way to get instead
    NDIV0(y/z) = <b>1</b> if z=0
    It is for the calculation of an indicator where "z" is the number of Outstanding problems and "y" is the number of Oustanding problems less than 30 days old. Therefore, if number of Outstanding problems (z) is equal to "0" (then y should also be equal to 0), you are OK and you should get a 1 (or 100%) score.
    Any help would be welcome!

    Hi Philippe,
        Based on the input you gave in the second part I would suggest you to go as I said below.
    In a new selection just take values for Z
    Similarly for Y.(Hide this)
    <b>It is for the calculation of an indicator where "z" is the number of Outstanding problems and "y" is the number of Oustanding problems less than 30 days old. Therefore, if number of Outstanding problems (z) is equal to "0" (then y should also be equal to 0), you are OK and you should get a 1 (or 100%) score.</b>
    As per your saying we can do the following.
    Take new formula and write as below:This firmula in report represents value for Y
    (z==0)*0
    Which means if Z is equal 0, the value for Y will be shown as zero in the report.
    Now to assign point you can create another new formula as below:
    (nodiv(y/z==0)*1
    This will give you the required output.
    Hope this helps you......

Maybe you are looking for

  • Import Po duty  change

    Hi Experts,            One Import PO Duty amount was entered wrong and part qty goods are in warded in the same,whether we can make changes and correct the duty amount in the same. We tried correcting and amending the PO with the correct duty value b

  • I have PURCHASED iTunes music on my iCloud account. The music appears on my iPhone. How do I get selected music from my iTunes on my iMac into the Cloud?

    I have PURCHASED iTunes music on my iCloud account. The music appears on my iPhone. How do I get selected music from my iTunes on my iMac into the Cloud?

  • Personlization via Application-Specific iView Attributes??

    Hi Guru's Having read the book 'Maximizing Web Dynpro for JAVA', regarding the personlization options to webdynpro, I have some questions: The books shows that it is possible to create application specific attributes, which the end-user or the admini

  • Assinging new Organization in Multi-Org.

    We have a multi-org setup. We need two different set of Books - for the first SOB we are using an Organization (Set Up Business Group).For the second SOB, we are not able to define another Organization through HRMS. The problem is while defining Orga

  • Caching problem one

    Hi, I have written a small function with two input variables: Begda and endda. Both variables are marked as mandatory in the R/3 backend. Now I have used it in a VC. In the test function both variables are marked as mandatory. So fare so good...... b