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.)

Similar Messages

  • Sapscript: How to combine two elements into a block when display ?

    /E  ITEM_CONDITIONS
    /:   PROTECT
    ZC &KOMVD-VTEXT&,,&KOMVD-KWERT&
    /:   ENDPROTECT
    /E  TOTAL_AMOUNT_ITEMS
    /:   PROTECT
    ZC &KOMK-SUPOS&
    /:   ENDPROTECT
    Hi, all. May i know how to combine the two elements into a same block when displaying?
    That's mean this two element content will not be split into two part between two pages when there is insufficient space in the front page.
    Thanks.
    Edited by: Jiansi Lim on Oct 8, 2008 12:24 AM

    You can evoke the PROTECT..ENDPROTECT in the print program before the call of the text elements.
          CALL FUNCTION 'CONTROL_FORM'
            EXPORTING
              command = 'PROTECT'.
          CALL FUNCTION 'CONTROL_FORM'
            EXPORTING
              command = 'ENDPROTECT'.

  • How to arrange two items into a row in the webdynpro provided by SAP?

    I am trying to custormize the ESS personal information - address info.
    My question is that how to put two separate items (like City and Address) into a same row?
    That is to change
    City: xxx
    Address: bbb
    to
    City: xxx     Address: bbb
    ps: I didn't got the NWDI, former changes were made by the ctrl + right clk.
    Thanks in advance!

    Hi,
       As like Shemim said, you can set the RootUIElementContainer layout property as Matrix Layout and in the UI Element (ie. label), Change the layoutdata property to MatrixHeadData to start in New line and to the show in the label in same line, set layoutdata property to MatrixData
    Regards,
    Venkatesh. K
    /* Points are Welcome */

  • How to Combine two queries into One

    Hi Gurus,
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    SQL>
    I have following two queries. How I can convert these two queries into one with the same result ?
    Q1
    SELECT id,vdate,vendorname,venddate,vid
    FROM VENDOR
    WHERE processid=32
    AND venddate is null
    AND vid in(select vid from view_vid where type='PDX')
    AND (id,vdate) not in (select id,vdate from vkfl_is where task_id=55)
    AND (id,vdate) in (select id,vidate from market_data where marketed_date is null)
    AND id not in (select id from location)
    Q2
    SELECT id,vdate,vendorname,venddate,vid
    FROM VENDOR
    WHERE processid=20
    AND venddate is null
    AND vid in(select vid from view_vid where type='PBX')
    AND (id,vdate) not in (select id,vdate from vkfl_is where task_id=40)
    AND (id,vdate) in (select id,vidate from market_data where region_date is null)
    AND id not in (select id from location)
    I can UNION these two queries, but, is there any way I can write a single query with which gives me same result as above two queries?
    Any help would be highly appreciated
    Thanks in advance

    Hi,
    You can do something like this, which will be more efficient than a UNION:
    SELECT  id, vdate, vendorname, venddate, vid
    FROM  vendor
    WHERE  (   (    -- Conditions that apply only to q1
                               processid = 32
                AND  vid       IN (SELECT vid FROM view_vid WHERE type = 'PDX')
                AND (id,vdate) NOT IN ( SELECT id, vdate
                                        FROM   vkfl_is
                                        WHERE  task_id = 55
                AND (id,vdate) IN ( SELECT id, vidate
                                    FROM   market_data
                                    WHERE  marketed_date IS NULL
            OR  (  -- Conditions that apply only to q2
                     processid = 20
                AND  vid       IN (SELECT vid FROM view_vid WHERE type = 'PBX')
                AND (id,vdate) NOT IN ( SELECT id, vdate
                                        FROM   vkfl_is
                                        WHERE  task_id = 40
                AND (id,vdate) IN ( SELECT  id, vidate
                                    FROM  market_data
                                    WHERE  region_date IS NULL
                   -- The remaining conditions apply to both q1 and q2
    AND     venddate   IS NULL
    AND     id         NOT IN (SELECT id FROM location)
    I hope this answers your question.
    If not, post  a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to Combine Two SubPaths into a Single SubPath

    For CS 5, ActionScript:
    I have a Path which contains two subpaths, which may or may not overlap.
    How do I combine them into a single SubPath (i.e., union) via scripting?
    I know that in the GUI, I can select both SubPaths and then press the "combine" button - this is the effect I want.
    TIA,
    mlavie

    This should combine the first path in the Paths Panel:
    // 2012, use at your own risk;
    #target photoshop
    if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    if (myDocument.pathItems.length > 0) {
    myDocument.pathItems[0].select();
    // =======================================================
    var idcombine = stringIDToTypeID( "combine" );
        var desc10 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref7 = new ActionReference();
            var idPath = charIDToTypeID( "Path" );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref7.putEnumerated( idPath, idOrdn, idTrgt );
        desc10.putReference( idnull, ref7 );
    executeAction( idcombine, desc10, DialogModes.NO );

  • How to concatenate two colums into one single column

    I need some ideas to concatenate two different columns into one single column using a set of distinct values.
    For Example,
    Customer Product Number
    xyz A 1
    xyz B 2
    xyz B 1
    AAA C 7
    AAA A 1
    The result should look like this,
    Customer Value
    xyz A1 B2 B1
    AAA C7 A1
    How would I group this into once value ?
    Thanks in advance ...

    Tom's discussion of writing your own aggregate routines
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2196162600402
    starts off with a link to the 8i alternatives
    "see
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:229614022562
    for 8i methods (not aggregates)"
    Unforutnately, it's a lot more work in 8i.
    Justin

  • How to turn two users into one?

    Hey there!
    As I selled my MBP last month I copied all its datas to my iMac via migration assistant and created a new user for it. So I have now two accounts with different photos, documents etc.
    My problem now is how to turn these two users into one?
    I want all my photos appear in Aperture of my first user, I want all my documents appear in "Documents" of the first user and so on..
    Is it able? If yes, how could I realize it?
    Thanks for your support!
    René
    PS: 2 Users on iMac -> 1 User on iMac.

    Thanks for your help at first.
    But you usually can't "merge" two "normal" user accounts successfully.  If both accounts have data for the same application, it will be very difficult or impossible to merge them by copying files & folders.
    I cannot merge them.. So there is the question how to copy all medias from Aperture to my other Aperture medias?
    Can I export my whole medias and import in at the other users Aperture? And how? #
    Edit: I dont want to have two different libraries at all.. I want them to be together in just one..

  • How to combine two albums into one

    I imported into iTunes two Shostakovich compositions so that I could burn a CD-R that contained these two works. The CD burning went fine, but iTunes insists on separating the two compositions into two albums in the display of all albums. I have made sure that the album titles and the artists displayed under the album icons are identical, but still the two will not meld into one. Will someone help me with this? I am using iTunes 9.2.1(4).

      On the "Get Information" windows (reached with right clicks) of the two separated albums, one album was marked as "no" on the "part of a compilation" option and the other was marked "yes". I changed the "no" to a "yes" and they merged. I'm not sure if I got this from the site you gave me or if I just stumbled on to it. Either way, I thank you for your kind responses.

  • Satellite L40-18Z: How to merge two partitions into one partition?

    Hello,
    I have a satellite L40 with a hard disk drive partitioned into two ( C and E ), one having 37GB capacity the other almonst 36 GB.
    The C drive is almost full and the E drive almost empty. I would like to take away the partition and have just one drive, is this possible.
    Any advice would be gratefully received. I am not a techi so be kind.
    Regards
    Peter

    Hi
    Of course this is possible
    You can do this in disk management.
    Just click right on My Computer -> Manage
    Here choose disk management.
    Now you have to delete the E partition. Then the free space could be added to the C partition.
    But note; before you would do this, create the recovery disk (if you didnt this in the past.)

  • How to make two files into one?

    I got two .iso files I would like to make into one file.
    What program can I use for this process? And step-by-step if possible.

    For disk images, if either of them is a read/write image, you can simply mount them both, drag the contents of one into the contents of the other, and unmount again. (Edit: just re-read your post; .ISO files are read-only so you will need to either follow the below instructions, or convert the ISO to a read/write DMG by dragging it into the left panel of Disk Utility and using the Images-Convert menu.)
    If they are both read-only, you'll need to create another disk image to contain them - use Disk Utility for this (File - New - Blank Disk Image), set the required size and properties, and once it's mounted, drag the contents of both .ISO images into it.
    Matt
    Message was edited by: Matt Clifton

  • How to turn a byte[] into an image?

    My app downloads image data from a server, storing the data in a byte[] called imageDataByteArray.
    I want to use imageDataByteArray to create an image. For this, I have tried using:
    int w = imageWidth; //488
    int h = imageHeight; //245
    int imageOffset = 0;
    int scan = w;
    Image image = component.createImage(new MemoryImageSource(w, h, java.awt.image.ColorModel.getRGBdefault(), imageDataByteArray, imageOffset, scan));
    ...but the image created is empty.
    I think the length of imageDataByteArray is a problem - it's length is only 21461, whereas the number of pixels in the image ( = imageWidth * imageHeight) is 119560.
    I've played around for a while, but cannot solve. Can anyone help?

    Hiya Rodney,
    Yes, it's in jpg format. I've tried your code but the image does not display correctly.
    To shed some more light, here's how I'm getting the image:
    I am using standard http code to connect to the image url (http://www...../image.jpg) which returns the image data as a String, called httpContent. I then convert this String to imageDataByteArray with httpContent.getBytes[] - but am obviously struggling to recreate the image.
    Any ideas where I might be going wrong?
    Thanks,
    James

  • How to club two rows into one

    hi
    Can we club two rows of a SQL statement into one , that is some column results from one row and other column result from second row, but the row must remain same .
    thanks
    imran

    SQL> with sample as (select 'A' supplier, 1000 total, 0 branch_total from dual
      2                union all
      3  select 'A' supplier, 0 total, 500 branch_total from dual
      4                union all
      5  select 'B' supplier, 300 total, 0 branch_total from dual
      6                union all
      7  select 'B' supplier, 0 total, 120 branch_total from dual)
      8  SELECT SUPPLIER , SUM(TOTAL) , SUM(BRANCH_TOTAL) FROM SAMPLE
      9    GROUP BY SUPPLIER
    10  /
    SUPPLIER SUM(TOTAL) SUM(BRANCH_TOTAL)
    A              1000               500
    B               300               120

  • How to copy Two universes into a Single universe

    Hi ,
    I am working on SAP BO 3.1 Designer ,
    I have three universes namely A,B& C which are pointing to same data base and with the same connection
    now I would like to combine the universes
    can u please suggest me on this..
    I would like to have the components of Universe A & B. in universe C..
    Thanks In Advance..

    Hi,
    I think, you are asking for the linking of multiple universes into a single universe and this is compatible with SAP BO 3.1 Designer
    Steps to Link Multiple Universes to a Single Universe with same Database and Connection
    1. Create a Universe A (for instance) with proper parameters mentioning the Database and Valid Connections
    2. Go to File >> Parameters >> Links tab and then Click Add Link
    3. Then point the Universe B you wish to link
    4. Similarly add a link to the other Universe C and then export the the Universe after saving to the repository.
    ** These universes are dynamically linked to the universe and the Objects, classes will be made available.
    Thanks and Regards,
    Arul Frances S

  • How to Print two layouts into one page

    Hi,
    I have developed a report by blocked ALV.In this report i have created two blocks.
    But when i give print out the two blocks are not printing continuously.It is displaying one block in one page and another block in anther page.
    And i need page number at end of each page.
    Please provide me solution for this.
    Thanks & Regards
    Venkatrami Reddy B

    OOPS – OO ABAP
    http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
    http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
    http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
    http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
    http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
    http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
    http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
    http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
    Reports
    http://www.sapgenie.com/abap/reports.htm
    http://www.allsaplinks.com/material.html
    http://www.sapdevelopment.co.uk/reporting/reportinghome.htm
    http://www.sapfans.com/forums/viewtopic.php?t=58286
    http://www.sapfans.com/forums/viewtopic.php?t=76490
    http://www.sapfans.com/forums/viewtopic.php?t=20591
    http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
    Rewards if useful.........
    Minal

  • HOW TO EXECUTE TWO "INSERT INTO" IN ONE SQL QUERY?????

    i have try the following:
    INSERT INTO tab VALUES('a','b');
    INSERT INTO tab VALUES('c','d');
    and
    INSERT INTO tab VALUES('a','b');
    INSERT INTO tab VALUES('c','d');
    but does not work in ORACLE 10G XE
    please help!!

    It is working fine in Oracle 10g.
    SQL> desc emp_t;
    Name                                      Null?    Type
    EMPNO                                              NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)And the script is --
    insert into emp_t values(7799,'Ani','CLERK');
    insert into emp_t values(2233,'Rupak','SW');  --File Name is a_a.sql
    commit;And, now from command prompt --
    SQL> set serveroutput on
    SQL>
    SQL>
    SQL> set lin 1000
    SQL>
    SQL> select * from emp_t;
         EMPNO ENAME      JOB
          7777 Avik       CLERK
          6666 prithwi    CLERK
          7639 Roni       CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
         EMPNO ENAME      JOB
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 BARRY      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
          5639 Atul       CLERK
    17 rows selected.
    SQL> @C:\Personal\RND\Oracle\Misc\a_a.sql;
    1 row created.
    1 row created.
    Commit complete.
    SQL>
    SQL>
    SQL> select * from emp_t;
         EMPNO ENAME      JOB
          7799 Ani        CLERK
          2233 Rupak      SW
          7777 Avik       CLERK
          6666 prithwi    CLERK
          7639 Roni       CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
         EMPNO ENAME      JOB
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 BARRY      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
          5639 Atul       CLERK
    19 rows selected.Regards.
    Satyaki De.

Maybe you are looking for

  • Upgrading to 7.5

    I was upgrading to 7.5 like a good boy when I get an error stating that "some necessary files are missing, to reinstall intunes." I have unistall and reinstalled several times both itunes & Quicktime with no success. Itunes will not open at all. I ge

  • Moving pictures in iphoto event

    Once you have created an event with your pics how can you adjust and move your pics around within that event, so that they are in the order you want them. New user to MAC!!!

  • Cffile accept

    Hi i have a file upload which i need to only accept CSV files, i have 2 problems with the code below 1. i have tried uploading a csv file but i get an error, do i need to add more to the accept clause? 2. if a user uploads a differnent mime type how

  • 12 months rolling forecast

    I am trying to write a calc script that should be able to do 12 months rolling forecast in one of our cubes. The months are the fourth gen of dimension "Period", "Year" has FY07, FY08, FY09.... in it and the "Scenario" has projection, budget, forecas

  • HRMS reports - help again

    do we have any oracle report in oracle HRMS that talks about Service award list i need to have them generated using oracle discov