Storing array of single bits

Hi, I have an object in my application which is hogging memory as there is up to 3million
of them in memory at one time and i am trying to cut down the size of it.
the core data structure is an array of 1's and zero's.
currently i'm using a byte[] to store these.
Because i know i only ever want to store a 1 or a 0 at each index, is there a way of storing
these as a boolean[] {1bit of storage in my understanding} so that i can save memory

Here's an example of packing 8 of your bytes from the array into a byte, then unpacking it into a String.
        byte[] ba        = {0, 0, 1, 0, 1, 0, 1, 0};
        // when packed into a byte the array value is decimal 42
        //Pack a byte
        byte packedByte  =
            (byte) ((byte) ((ba[0] & 0xf) << 7) |
                    (byte) ((ba[1] & 0xf) << 6) |
                    (byte) ((ba[2] & 0xf) << 5) |
                    (byte) ((ba[3] & 0xf) << 4) |
                    (byte) ((ba[4] & 0xf) << 3) |
                    (byte) ((ba[5] & 0xf) << 2) |
                    (byte) ((ba[6] & 0xf) << 1) |
                    (byte) ((ba[7] & 0xf) << 0));
        System.out.println("The byte value is " + packedByte);
        //Unpack a byte
        String UnpackedByte = Integer.toBinaryString(packedByte);
        System.out.println("The binary string is " + UnpackedByte);

Similar Messages

  • Streaming multi bit rate and single bit rate

    I'm trying to simplify my setup.  Sometimes I need to stream multi bit rate and sometimes I need to stream single bit rate.  This is due to the internet connections I'm sending from sometimes have poor upstream and multi-bit rate is too much bandwidth to send... So....  We resort to single bitrate.  As I understand my encoder and server settings are different for each of these...  I created a single and multi-bitrate profile for Adobe Media Encoder.  That was simple enough.  My question/concern is in regards the server settings.  I would like to have a server setting for multi-bitrate and a setting for single bit rate.  My goal is to void making changes  on the server.  I simply want to load the desired Adobe Media Encoder Profile.  So, do I need to create a dedicated event for single bitrate?  Below is the syntax I send to my server from Adobe Live Encoder.  Instead of using 'liveevent' for my event would I just give it a different name?  Does this stand true for my .m3u8 files?  I'm confused to how to name differnet event/streams.... 
    livestream%i?adbe-live-event=liveevent&adbe-record-mode=record

    Hi,
    When you use a setting like: livestream%i?adbe-live-event=liveevent then the encoder expects multibitrate streams (the %i is replaced by a number so the streams published will be livestream1, livestream2 and livestream3). You cannot use the same setting in the encoder for single stream. Instead you'll have to use livestream?adbe-live-event=<event_name>. You could create a new event under the same application.
    Hope this helps. Let me know if you have any other queries.
    Thanks,
    Apurva

  • Change 1D array of 32 bit integer to 1D array of BV tag

    i just want to change 1D array of 32 bit data type to 1D array of BV tag to display this in Historical trend viewer
    an urgent reply wud b highly appreciable
    VINO

    What you are asking for is not really clear for me... I assume you want your array of numeric values to be replaced by a boolean array.
    Also, I was not sure about what numeric value has to correspond with TRUE or FALSE...
    Here is a possibility to do this :
    I hope this will help you...
    Message Edité par TiTou le 03-29-200609:07 AM
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    QH.png ‏6 KB

  • Single bit error in X2200 and rebooting frequently

    I have X2200 M2 server rebooting frequently with single bit error with amber led in the memory with one cpu location but if i swap that error will go and there is no amber led system is running fine but frequently i am getting same issue.
    I am using the applications simulators like hspice64, spectre, ultrasim64
    system configuration is linux rhel 4 update 4 32gb memory.
    is it a bug or any hardware compatibility issue is there in that application or box kindly let me know.
    my mail id [email protected]

    Upgrade the ilom and BIOS frimware to latest if its low . Run PC check utility by downloading from www.sun.com and if the problem remains the same log a ticket with Sun for further investigating . collect the logs from ILOM and IPMI prior to logging the ticket .
    Ravi

  • How to find whether a text is single bit or double bit?

    Hi All,
      We have a requirement to restrict the user from entering any double bit characters in a text field. Words in English and numbers can be allowed. If anything apart from this, an error message needs to be given. Is anybody aware of how we can find if a character entered is a double bit or not?
    Thanks in advance.
    Saritha

    Hi,
    try this code.
    REPORT abc.
    PARAMETERS: p_text(10) TYPE c.
    CONDENSE p_text.
    IF NOT p_text+1 IS INITIAL.
      MESSAGE 'Error: Enter single bit' TYPE 'E'.
    ENDIF.
    IF NOT ( p_text CA sy-abcde OR p_text CA '0123456789' ).
      MESSAGE 'Please enter alpha numeric' TYPE 'E'
    ENDIF.

  • What is the most efficient way to turn an array of 16 bit unsigned integers into an ASCII string such that...?

    What is the most efficient way to turn a one dimensional array of 16 bit unsigned integers into an ASCII string such that the low byte of the integer is first, then the high byte, then two bytes of hex "00" (that is to say, two null characters in a row)?
    My method seems somewhat ad hoc. I take the number, split it, then interleave it with 2 arrays of 4095 bytes. Easy enough, but it depends on all of these files being exactly 16380 bytes, which theoretically they should be.
    The size of the array is known. However, if it were not, what would be the best method?
    (And yes, I am trying to read in a file format from another program)

    My method:
    Attachments:
    word_array_to_weird_string.vi ‏18 KB

  • OPC data tag-single bit

    I am trying to read OPC data tags using LabView 6.0
    For bit data, the tag list says 1=ON, 0=OFF
    What data type should I use to read and write a single bit?
    I have tried I8 and boolean, but neither seem to work.

    Here is the read tag byte data as viewed from the OPC server explorer.
    The send tag is similar structure.
    Again I can use data socket to read (or write)the entire byte, but I don't
    know how to address individual bits
    Attachments:
    OPC Byte and Bit-read.JPG ‏94 KB
    OPC Byte and Bit-write.JPG ‏83 KB

  • DIMM 4 has single-bit error

    This is an Warning message that got on the Embedded Lights Out manager of an X2200M2 server:
    "DIMM 4 has single-bit error"
    I also have a orange flashing light on front of the server.
    What does it mean exactly ?

    Glance through this forum thread from May 2006:
    http://forum.java.sun.com/thread.jspa?forumID=830&threadID=5097092
    Then use your contract login to Sunsolve and read the following Infodocs:
    70361
    79928
    74049

  • Storing arrays in a single file!!

    Hello all,
    Is it possible to store two arrays into a single file either separately or together as a POJO. How to accomplish this??..Need some guidance

    try DataInputStream and DataOutputStream
    ObjectInput/OutputSTream is used to store Object which use more space.

  • Rebuild 1d array in single 32 bit integer

    Hi, i have a problem
    in my measurement i get permanently measurement data as an 1d arrays. This data goes in a queue, and from there i want to unpack this array in a singel 32 integer word stream and this very very fast, because the measurement data input is up to 50 MHz.
    The question is: How can i unpack this 1d array in a single 32 word stream???
    THX for answer
    there is a picture, where you can see the measurement data in put in this queue and the data output.
    Attachments:
    array.jpg ‏212 KB

    As Mike already indicated, all you need is a "-3" shift (or scale by 2^-3). On integers, both are identical, so use the one that better documents the code for readability.
    You actually only have an array with a single element, so you should leave the "count" unwired to get a scalar output instead. No need to index out later. (top image)
    If you want to read the entire array at once, wire a -1 to the count and do the same operation on the entire array. (bottom image)
    Simple as that! 
    Message Edited by altenbach on 01-06-2009 09:52 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Scale.png ‏4 KB

  • How do I write whole array in single write ?

    Hi Jgurus,
    I have fetched the record from Oracle and I wants to write those in a file . But problem is for every record in a record set file.writebytes write to a OS file. I don't want this single record write since it will write one by one. I have crores of records to fetch. Critical issue is performance. Can I picked up the rows in bunch and write to file ? I have stored (on smaller record size) all rows in array and now want to write the whole array to file in one OS write operation. Is there any way to do this ? Do any one suggest the better approach ?
    For real scenario file size will become around 300MB. I did it but it writes one by one record using next() from record set.
    Please advice.
    --RajivK.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Can you give any example for a small String or int array. I have stucked at this point. I have wrote the array using for loop but for each iteration in a loop it writes. I have 5 lakh values stored in array. Can anybody show how do write whole array to os file in one write operation instead of getting one by one value and printing it. I am new to java please give details or sample so that I can understand.
    Thanks in advance.
    --RK.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to decide if Object is an array or single object

    Hi ,
    I have a function which can return an Array of objects or a single Object...how can I decided what function has returned to me.?...
    I am looking for some way by which I can decided if it is an Array or a Object....
    Thanks

    How about:
    yourObject.getClass().isArray();  // returns boolean

  • Storing Array of Floats as a BLOB

    I am designing a new laboratory database. For some tests, I have several waveforms with ~10,000 data points acquired simultaneously. In the application (written in C), the waveforms are stored as an array of floats.
    I believe I would like to store each waveform as a BLOB.
    Can the data in a BLOB be structured in such a way that Oracle can work with the data itself using only SQL or PL/SQL?
    * Determine max, min, average, etc
    * Retrieve index when value first exceeds 500
    * Retrieve 400th number
    * Create BLOB which is a derivative of first BLOB

    Let me start from your last question should I use BLOBS?, the answer is simple - NO, why the hell do you need to store is on BLOB's, you are talking about 6,000,000 rows per day it avarag no more, uses reular tabular reprisentitiona and you will be able to query the data properlly.
    1. If I decide to use a BLOB then the calculations must be performed in the application. Correct? - Yes
    2. In order to query on data derived from the raw data, the result of any calculations must be re-inserted into the database. Correct? - Not exacly.
    3. Considering the quantity of data and how I want to use it, should I use BLOBS? - Regulat tabular represintition, and you can archive the data after X day or use summery tables.

  • IMAQ Array to Image Bit Shift?

    Hi,
    I've been working with some 12 bit images from a camera and saving the results as 16 bit TIFFs using some of the Vision VIs.  I can save and read back in the TIFFs and all of the data stays intact, but if I try to open the saved TIFFs in another reader (e.g. MATLAB), the returned data is incorrect.  Opening the raw TIFF files and looking at the image data (little endian) in bytes, numbers like 234 001 [490] end up becoming 234 129 [33258].  From the attached VI, it becomes clear there's a problem when you simply put in zeros to the array and try to open up the resultant TIFF in MATLAB (0 goes to 2^15) and yet LabView reads in the TIFF just fine.  While I can work around this problem, I only know I that need to work around it if I know a priori that the TIFF is from LabView.  Is there some resolution to this problem?  I'm thinking some kind of bit shifting to the data in LabView before converting the array to an image.  Thanks.
    Attachments:
    array_to_tiff.vi ‏49 KB

    Hello,
    Maybe you are looking for the functions "swap byte" and "swap words"
    Hope this helps
    Message Edité par TiTou le 06-29-2007 02:00 PM
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    swap.png ‏409 KB

  • Storing integer as a bit to have storage management

    I have this matrix(size:10x6000) which only stores integers 0 and 1 and what my program does is, it compares each row with all the other rows underneath it and do the XOR operation on the elements stored at the corresponding locations and as a result the new matrix i get may or maynot have more rows that were in the original matrix.
    My question:
    As all the elements are either 0 or 1 ...i can treat them as bit 0 or bit 1.How to do that and store that as 1 bit instead of 16 bits.I will be able to save a lot of space by this way.
    I need this very urgently....!!!!

    I have this matrix(size:10x6000) which only stores
    integers 0 and 1 and what my program does is, it
    compares each row with all the other rows underneath
    it and do the XOR operation on the elements stored at
    the corresponding locations and as a result the new
    matrix i get may or maynot have more rows that were in
    the original matrix.
    My question:
    As all the elements are either 0 or 1 ...i can treat
    them as bit 0 or bit 1.How to do that and store that
    as 1 bit instead of 16 bits.I will be able to save a
    lot of space by this way.
    I need this very urgently....!!!!
    ANSWER: Using the int to store a Bit would definetly multiply the storage space by 16 times. Hence i would redomend you to use the Java.util.BitSet class .This would save a lot of space as it is specially designed to store bits. If you have any doubts - [email protected]

Maybe you are looking for

  • Media Encoder CC 14 renders with black frame at the end

    Hello, my Media Encoder running on Mac Yosemite makes a black frame at the end of h264 clips... How can i fix this? Thanks

  • Msging anyone online makes them go offline and pen...

    I am having a problem where I am sending msgs to people that are online and everytime i do it shows the person go from online to offline and then pends. Also my old msgs are not showing up. I know that these people are online because my phone skype w

  • Why is jpeg file size different in CS 5 and Photoshop CC?

    If I open a jpeg file in both CS5 and Photoshop CC, and then "save" the files, the file from CC is much smaller than the file from CS5. The size and compression ratios are the same, but the file size is different.  (It is about 1/2 the size).

  • RV042 Shrew soft client NAT-t new mapping

    Hi everyone, Since I had Quick VPN issue, so I tried the Shrew soft client hoping to get the IPSec tunnel with router RV042 in Client2gateway mode. On Shrew client, I got "Tunnel is activated" but got establised failed errors. On RV042 IPSec log, it

  • 6680 and car kit10

    When the phone is in the cradle and I receive an incoming call the stereo unit does not mute, whoever it does mute when using the 6230 model