Converting 16 Bit Integer to Individual Bits

I have a 16 bit Binary Integer and I need to convert this into Individual bits so we can perform some data manipulation.  I know there is a easy solution, but I just cant figure it out.  I attached what I was trying to do, remove the 16 bits and make a 1D array with 16 elements, then remove each element from the array.  This may be the wrong approach to this problem.  Any help would be appreciated.  Thanks in advance.

It seems your input is a I16 integer, so it is really bad to have the representation of the control as U32. Makes no sense.
Anyway, here's a quick alternative that seems to give the desired result with a code size of less than a postage stamp. see if it works for you.
(note that we get different results for some input values. Do you have the original documentation for the conversion?)
Message Edited by altenbach on 05-09-2007 10:25 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
scaleInteger.png ‏4 KB
ScaleInteger.vi ‏38 KB

Similar Messages

  • 16 bit integer vs 32 bit floating point

    What is the difference between these two settings?
    My question stems from the problem I have importing files from different networked servers. I put FCP files (NTSC DV - self contained movies) into the server with 16 bit settings, but when I pull the same file off the server and import it into my FCP, this setting is set to 32 bit floating point, forcing me to have to render the audio.
    This format difference causes stuttering during playback in the viewer, and is an inconvenience when dealing with tight deadlines (something that needs to be done in 5 minutes).
    Any thoughts would be helpful.

    It's not quite that simple.
    32 bit floating point numbers have essentially an 8 bit exponent and 24 bit mantissa.  You could imagine that the exponent isn't particularly significant in values that generally range from 0.0 to 1.0, so you have 24 bits of precision (color information) essentially.
    At 16-bit float, I'm throwing out half the color information, but I'd still have vastly more color information than 16-bit integer?
    Not really.  But it's not a trivial comparison.
    I don't know the layout of the 24 bit format you mentioned, but a 16 bit half-float value has 11 bits of precision.  Photoshop's 16 bits/color mode has 15 bits of precision.
    The way integers are manipulated vs. floating point differs during image editing, with consistent retention of precision being a plus of the floating point format when manipulating colors of any brightness.  Essentially this means very little chance of introducing posterization from extreme operations in the workflow.  If your images are substantially dark, you might actually have more precision in a half-float, and if your images are light you might have more precision in 16 bits/channel integers.
    I'd be concerned over what is meant by "lossy" compression.  Can you see the compression artifacts?
    -Noel

  • Read an excel file and convert to a 1-D array of long, 32-bit integer?

    My vi right now reads an column of numbers as a 1-D array, but I need to input the numbers manually, and for what I'm trying to do, there could be anywhere between 100 to 500 numbers to input. I want the vi to be able to read the excel file and use that column of numbers for the rest, which the data type is long (32-bit integer).
    I have an example vi that is able to get excel values, but the output data type is double (64-bit real).
    I need to either be able to convert double(64-bit real) data to long (32-bit integer), or find another way to get the values from the excel file.

    Just to expand on what GerdW is saying.  There are many programs that hold exclusive access to a file.  So if a file is opened in Excel, the LabVIEW cannot access the file.
    What is the exact error code?  Different error codes will point to different issues.
    Make sure the csv file is exactly where you think it is and LabVIEW is pointing to the right place.  (I'm just going through stupid things I have done)
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How can I set specific bits in a 16-bit integer?

    Hello everyone,
    as the title says I need to modify or rather to set a specific bit in a string which then is sent to a motor. I need to be sure that my command is correct as I am experiencing troubles with that motor and need to identify if its source.
    First of all my strings have to be in the Little Endian order. Then the structure of the string should be the following:
    Change Velocity command ‘V’xxCR 056h + one unsigned short (16-bit) integer + 0Dh (Note: Uppercase ‘V’)
    Note: The lower 15 bits (Bit 14 through 0) contain the velocity value. The high-order bit (Bit 15) is used to indicate the microstep-to-step resolution: 0 = 10, 1 = 50 uSteps/step.
    Until now, I used Flatten To String to convert 32 bit integers into bytes of the correct order. I thought I could use the Join Numbers function, but that only works for at least 8 bit numbers and there is no "1 bit number". I searched for an option to build a a string and set the bits via a Boolean Cluster, but I did not really understand how to transfer this to my problem.
    How can I build up the correct 16-bit integer (e.g. set the velocity to "10000" with a resolution of 50 µSteps/step)
    I would like to add the "V" and the CR via Concatenate Strings to the 16-bit integer, but other possibilites are also welcome.
    I have seens the examples for bit manipulation in C-code, but I wish to do this with LabView as I am not familiar with C,matlab and so on.
    Thank you very much for your help!
    Solved!
    Go to Solution.

    You really need to learn Boolean logic and how to shift bits around.
    AND is really good for masking out bits (forcing them to 0) and OR is really good for adding bit values.  Then Logical Shift is used to get the bits in the right places before doing the AND and OR.
    NOTE: Rate is an enum with 10 being a value of 0 and 50 being 1.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Bit Packing.png ‏15 KB

  • Using bitwise operators to swap individual bits

    I'm able to set or clear individual bits using masks, however I'm trying to figure out how I could go about swapping two bits using bitwise operators but I haven't been able to figure it out. For example, say I had int x = 37 which is 100101 in binary and I wanted to swap the 2nd and 3rd bits I'd like to get 100011 when I use Integer.toBinaryString(x) after performing some bitwise operations on x to swap bits around. Any suggestions ?

    How about something like this? A preliminary test seemed to work.
    class BitSwap2 {
      public static void main(String[] argv) {
        int x = 37;
        System.out.printf("Binary: %s\n", Integer.toBinaryString(x));
        swapBits(x, 2, 3);
      private static void swapBits(int x, int a, int b) {
        if(a == b) {
          System.out.printf("Nothing to swap.\n");
          return;
        int first = (x & (1<<(a-1)));
        int second = (x & (1<<(b-1)));
        // zero them out from the original so that we can swap them
        x ^= (first | second);
        if(a > b) {
          int diff = (a - b);
          x |= (first >> diff);
          x |= (second << diff);
        } else {
          int diff = (b - a);
          x |= (second >> diff);
          x |= (second << diff);
        System.out.printf("Binary: %s\n", Integer.toBinaryString(x));
    }

  • How to look at individual bits of a short to see if 0 or 1

    I am writing a program in which i send a command to someone and get a response back in the form of a short.
    a short consists of 16 bits, how can i look at the bits individually to see if they are 1 or 0.
    forexample say the short that comes back in binary is
    in otherwords i want to start from the first bit and parse all of them to see if they are 1 or 0

    short num = (short)0xAAAB;   // binary '1010101010101011'
            int mask = 1;
            for(int n=1; n<17; n++) {
                 System.out.println("Bit " + n + " = " + ((num & mask) == mask ? "Set" : "Not set"));
                 mask <<= 1;
            }---------- Capture Output ----------
    "C:\WINDOWS\system32\java.exe" -cp . ZzBit 1 = Set
    Bit 2 = Set
    Bit 3 = Not set
    Bit 4 = Set
    Bit 5 = Not set
    Bit 6 = Set
    Bit 7 = Not set
    Bit 8 = Set
    Bit 9 = Not set
    Bit 10 = Set
    Bit 11 = Not set
    Bit 12 = Set
    Bit 13 = Not set
    Bit 14 = Set
    Bit 15 = Not set
    Bit 16 = Set
    Terminated with exit code 0.

  • 32 bit integer size on 64 bit processor and OS

    Although not strictly a dbx question, I think the audience here is the correct one to bounce this off of:
    I'm curious: Why are 64 bit processes compiled with the -xarch=v9 switch having a 32 bit integer size, versus having 64 bit integer size?
    Although not cast in stone, and implementation dependent, an "int was originally intended to be the "natural" word size of the processor - to use the processor's "natural" word size to improve efficiency (avoid masking, etc).".
    I know you 'force' more 64 bit use (see some of Sun's doc on this below).
    ===============
    The 64-bit Solaris operating environment is a complete 32-bit and 64-bit application and development environment supported by a 64-bit operating system. The 64-bit Solaris operating environment overcomes the limitations of the 32-bit system by supporting a 64-bit virtual address space as well as removing other existing 32-bit system limitations.
    For C, C++, and Fortran software developers, this means the following when compiling with -xarch=v9,v9a, or v9b in a Solaris 7 or Solaris 8 environment:
    Full 64-bit integer arithmetic for 64-bit applications. Though 64-bit arithmetic has been available in all Solaris 2 releases, the 64-bit implementation now uses full 64-bit machine registers for integer operations and parameter passing.
    A 64-bit virtual address space allows programs to access very large blocks of memory.
    For C and C++, the data model is "LP64" for 64-bit applications: long and pointer data types are 64-bits and the programmer needs to be aware that this change may be the cause of many 32-bit to 64-bit conversion issues. The details are in the Solaris 64-bit Developer's Guide, available on AnswerBook2. Also, the lint -errchk=longptr64 option can be used to check a C program's portability to an LP64 environment. Lint will check for assignments of pointer expressions and long integer expressions to plain (32-bit) integers, even for explicit casts.
    The Fortran programmer needs to be aware that POINTER variables in a 64-bit environment are INTEGER*8. Also, certain library routines and intrinsics will require INTEGER*8 arguments and/or return INTEGER*8 values when programs are compiled with -xarch=v9,v9a, or v9b that would otherwise require INTEGER*4.
    Be aware however that even though a program is compiled to run in a 64-bit environment, default data sizes for INTEGER, REAL, COMPLEX, and DOUBLE PRECISION do not change. That is, even though a program is compiled with -xarch=v9, default INTEGER and REAL are still INTEGER*4 and REAL*4, and so on. To use the full features of the 64-bit environment, some explicit typing of variables as INTEGER*8 and REAL*8 may be required. (See also the -xtypemap option.) Also, some 64-bit specific library routines (such as qsort(3F) and malloc64(3F)) may have to be used. For details, see the FORTRAN 77 or Fortran 95 READMEs (also viewable with the f77 or f95 compiler option: -xhelp=readme).
    A: No program is available that specifically invokes 64-bit capabilities. In order to take advantage of the 64-bit capabilities of your system running the 64-bit version of the operating environment, you need to rebuild your applications using the -xarch=v9 option of the compiler or assembler.

    I think that this was basically to keep down the headaches in porting code (and having code that will compile to both 32bit and 64bit object files). int is probably the most common type, so by keeping it at 32bits, the LP64 model has less effect on code that was originally written for 32bit platforms.
    If you want to have portable code (in terms of the sizes of integral types), then you should consider using int32_t, int64_t etc from inttypes.h. Note that this header is post-ANSI C 90, so might not be portable to old C/C++ compilers.
    A+
    Paul

  • Market requires versionCode to be set to a positive 32-bit integer in AndroidManifest.xml

    I have built an application on flash builder Buritto  using the tutorial of " Christophe Coenraets"  building an EmployeeDirectory  and everything worked fine while debugging it in virtual environment but when I try to upload it to the andoid market im getting the  following error  : and everything worked fine while debugging it in virtual environment but when I try to upload it to the andoid market im getting the  following error  :
    Market requires versionCode to be set to a positive 32-bit integer in AndroidManifest.xml
    how can I solve this issue
    help please !!!!!!!

    Where can I find my  manifest file ? so that I can change the value ?

  • How to convert a 16-bit image to 8-bit

    I am having difficulties in skeletonizing my image. Although I already threshold my image, it still cannot be skeletonized. When I create the image using IMAQ create, the image type must be set to 16-bit, otherwise it will create an error message. An enthusiast in the forum told me that the image must be 8-bit so that it can be skeletonized. But I do not know how to convert the image from 16-bit to 8-bit. So is there anybody out there that can provide me with a solution. Attached is the VI that I used. Really appreciate your help.
    Attachments:
    Image_Acquisition.vi ‏68 KB

    Try using the IMAQ Cast Image function under Motion & Vision>>Vision Utilities>>Image Management>>IMAQ Cast Image.
    Regards,
    Steve

  • 64 bits integer handling

    I can't find the way how to bind or define 64 bits integer using Oracle 8.1.7 OCI.
    Plz, tell me any effective way to handle 64 bits integer.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Shoaib ([email protected]):
    If 64-bit is the normal size of integer on your platform, then passing using SQLT_INT for data type and sizeof(int) should work for your bind and define calls.<HR></BLOCKQUOTE>
    Thank you for your comments.
    The normal size of integer in my current platform is 4 bytes, 32 bits. The current 64-bit type is "long long" type. The OS I tested are Compaq Tru64 Unix V5.1 and Linux . For "long long" type, SQLT_INT and sizeof(long long) has failed.
    As work around the 64-bits integer is fetched as string into SQLT_STR defined host variables. After that, conversion from string to integer is executed using atol().
    Any other good working alternative?

  • Read/Write unsigned 32 bit integer to BLOB

    Dear All,
    I am writing an array of unsigned 32 bit integers to a Blob field, using delphi. I can also read the same from delphi.
    In a stored proc, I need to read the unsigned 32 bit integer from the blob.
    I have used dbms_lob.read function.
    Here for dbms_lob.read(lob_loc,amount,offset,buffer)
    I've given
    lob_loc - the locator
    amount - 4 bytes
    offset - 1
    buffer- ?? The buffer here has to be a datatype which corresponds to unsigned 32 bit. Which datatype in oracle can be used here ? I tried to give raw, but it doesnot seems to give the required out put.
    Please help !!!

    What version of oraoledb? There were some issues with NUMBER datatype in earlier versions, I'd recommend testing the most recent version.
    To patch 10.2 oraoledb, apply the 10.2.0.4 database patch to the client install.
    Hope it helps,
    Greg

  • Converting JPEG to BMP 1 bit depth

    Hi
    I need to convert JPEG to BMP 1 bit depth (monochromatic)
    I've used this code, but the result is always a 24 bit depth BMP...
    How can I do?
    JPEGDecodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(1, JPEGDecodeParam.COLOR_ID_GRAY);
    JPEGImageDecoder jd = JPEGCodec.createJPEGDecoder(myByteArrayInputStream, param );
    BufferedImage bufferedImage = jd.decodeAsBufferedImage();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "bmp", baos);
    Thanks

    An application that you already have that can do the job is Preview. Open the file in Preview and do a Save As, seleting PICT as the end format.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Need conversion mechanism for converting 24 bit image to 16 bit

    In my java project I need to convert 24 bit image to 16 bit image. I don't have any clue. Please provide me the option to implement it.
    Thanks,
    jai

    That doesn't tell me much, and I know what you're talking about. I doubt that it tells the OP anything useful whatsoever.Sorry EJP, it was a mouthful I know. Maybe this will help instead, a ColorConversionOps class to work on *32 bit > 16 bit > 32 bit colors*. To help clarify where the 16 bit color input and output goes, some of the methods return or require parameters of type short. Also take notice the bitmask for variables of type short vs the bitmasks for int. AND pay particular attention to the unsigned right bit-shifting of the most-significant-digit.
    public class ColorConversionOps
      public static short convert32_16(int rgb) {
        int a = ((rgb & 0xF0000000) >>> 16);
        int r = ((rgb & 0x00F00000) >>  12);
        int g = ((rgb & 0x0000F000) >>   8);
        int b = ((rgb & 0x000000F0) >>   4);
        return (short)( a | r | g | b);
      public static int convert16_32(short rgb) {
        int a = ((rgb & 0xF000) << 16);
        int r = ((rgb & 0x0F00) << 12);
        int g = ((rgb & 0x00F0) <<  8);
        int b = ((rgb & 0x000F) <<  4);
        return (a | r | g | b);
      public static void printRGB_32(int rgb) {
        System.out.println("a="+((rgb & 0xFF000000) >>> 24));
        System.out.println("r="+((rgb & 0x00FF0000) >>  16));
        System.out.println("g="+((rgb & 0x0000FF00) >>  8));
        System.out.println("b="+ (rgb & 0x000000FF));
        System.out.println();
      public static void printRGB_16(short rgb) {
        System.out.println("a="+((rgb & 0xF000) >>> 12));
        System.out.println("r="+((rgb & 0x0F00) >>  8));
        System.out.println("g="+((rgb & 0x00F0) >>  4));
        System.out.println("b="+ (rgb & 0x000F));
        System.out.println();
    }Now to make the conversion from 32 bit color to 16 bit color and back. NOTICE there willl be a loss of precision -- just like someone else has already said.
    public class Test
      public static void main(String[] args)
        int rgb = 0xFFFFFFFF;
        ColorConversionOps.printRGB_32(rgb);
        //a=255
        //r=255
        //g=255
        //b=255
        rgb = ColorConversionOps.convert32_16(rgb);
        ColorConversionOps.printRGB_16((short)rgb);
        //a=15
        //r=15
        //g=15
        //b=15
        rgb = ColorConversionOps.convert16_32((short)rgb);
        ColorConversionOps.printRGB_32(rgb);
        //a=240
        //r=240
        //g=240
        //b=240
    }And now we see, the reason 16bit color is so unpopular to the rest of the world, but not for us here!

  • Can PSE8 for mac convert an 8 bit image to 16 bit?

    can Photoshop Elements 8 for mac convert an 8 bit image to 16 bit?
    I use Photomatix Pro and when I am working with a single image in Photomatix Pro, it has to be 16 bit.

    Yes, you can. These are the steps when using the elements editor.
    Depending on the file format:
    1. If this file is from a camera raw file, simply open the original
        raw file and at the bottom of the camera raw dialog choose 16 bits.
        This would open the file in pse editor as a 16 bit file.
        Then save as a tif file with no compression.
    2. If the file is a jpg or tif file, in the pse editor select: File>Open As>Camera Raw.
        This will open the file in the camera raw dialog. Then select 16 bit from the menu
        at the bottom of the camera raw dialog. After the file opens in pse editor, in 16 bits,
        save as a tif with no compression.
    3. If the file is a psd file with no layers, then step 2 will work. If the psd file has layers,
        open the the file in pse editor and resave the file using maximize compatibilty.
        This will allow the psd file to have both layers and open in the camera raw dialog as
        in step 2. When you open the file in the pse editor, it will just be a single layer and then
        just save as a tif file with no compression.
    Hope this helps.
    MTSTUNER

  • Convert a ( .BMP) onto row bits

    hi,i have a problem on how to take an image as an input
    and convert it into a row bit stream stored in an array
    if anyone has an idea,i'll appreciate sending me a demo source code
    thnx

    Depends what you need in the bit array. Check out javax.awt.image.PixelGrabber, see if it's anything like what you need.

Maybe you are looking for