Convert 8 bit unsigned integer to binary (base 2)

i am trying to convert an 8 bit unsigned integer to binary (base 2) representation and use 8 LED's to show this representation.
Like for integer 10, the binary is 00001010.....so the LED' s 1 and 3 should be on...

The LED (boolean) indicators are simply placed into an array.
To "borrow" an example of such a display, you could have a look at the code written for the parallel port example that can be found under the Help menu:
Help > Find Examples :  Search "parallel"  HAve a look at the 1st or 2nd example.  They have LED's wired to a U8 array  (I think..  It's been a while since I looked at the example...   )

Similar Messages

  • How to read 16-bit signed integer in binary format with 2 byte sync. preceding??

    A flowmeter provides data as 16-bit signed integer in binary format with 2 byte sync. preceding
    I got i small problem by understanding the synchronasation.
    I read the data provided by the flowmeter, and then write it to a binaryfile.dat. i need to convert the data to decimal format. is it better to convert the data before or after writing it to the binary file. Coz i need to read the data out again for calculations and save it again in a new file.
    I understand that the synchronization  help one to see where to begin reading the usable data. is it right?
    Need any suggestions
    Thank you !
    Zamzam
    HFZ
    Attachments:
    DataOut.JPG ‏37 KB

    HI Rolf.k.
    Thank you for the small program it was helpfull.
    You got right about that proberly there  will be conflict with some spurios data, I can already detect that when writing the data to a spreadsheet file.
    I writes the data in such a way, that in each line there will be a date, a timestamp, a tab and a timestamp at the end. That means two columns.
    When i set given samplerate up, that controls the rate of the data outflow from the device, (1,56 Hz - 200 Hz),   the data file that i write to , looks unorderet.
     i get more than one timestamp and severel datavalues in every line and so on down the spreadsheet file.
    Now the question is: Could it be that the function that writes the data to the file,  can't handle the speed of the dataflow in such a way that the time stamp cant follow with the data flowspeed. so i'm trying to set the timestamp to be  with fractions of the seconds by adding the unit (<digit>) in the timestamp icon but its not working. Meaby when i take the fractions off a second within the timestamp i can get every timestamp with its right data value. Am i in deeb water or what do You mean!??
    AAttached Pics part of program and a logfile over data written to file
    regards
    Zamzam
    HFZ
    Attachments:
    DataFlowWR.JPG ‏159 KB
    Datalogfile.JPG ‏386 KB

  • Convert unsigned integer to IEEE float

    Hello,
    Is there a typecast function in CVI that would convert 2 unsigned integers to IEEE loat?
    eg:
    1st value MSB:  50588
    2nd value LSB: 16425
    Actual reading:  -5000.02
    Thanks.
    TN
    Solved!
    Go to Solution.

    You just need to do some pointer manipulation to build your float.
    But you need to be aware of the size of the data types you're using.  Based on your example values, it looks like you are using the IEEE single precision format, which is 4 bytes.  In 32 bit operating systems, the unsigned int is also 4 bytes.  So you can't combine two unsigned int into an IEEE single without casting them as short ints, which are 2 bytes each.  You would need to check if the value in your unsigned int will fit in an unsigned short before casting it.
    You can play with the sizeof() function to see the data type sizes on whatever platform you're using.
    Here are a few lines of code the combine your example values to produce the expected result.
    #include <ansi_c.h>
    #include <utility.h>
    main()
     // allocate room for myFloat (IEEE single precision)
     float myFloat;
     // create pointers to the two words in the IEEE single precision format
     unsigned short *pMSW, *pLSW;
     // move the pointers to the first and second word in your float
     pLSW = (unsigned short *) &myFloat;
     pMSW = pLSW +1;
     // initialize the word values
     *pMSW = 50588;
     *pLSW = 16425;
     // print everything out
     printf("MSW: %d\tLSW: %d\tIEEE Single: %f\n", *pMSW, *pLSW, myFloat);
     // wait for a response
     printf("Press any key to continue...\n");
     GetKey();
    Here's a link to a discussion on going the other way, which has a sample program and links to more IEEE format info.
    http://forums.ni.com/t5/LabWindows-CVI/How-to-convert-a-number-to-32-bit-binary-or-Hex/m-p/977159#M4...

  • Php Pack/unpack unsigned integer equivalent

    I'm trying to port some PHP code into Java which contains calls to Pack and Unpack which I'm trying to use which I'm having some problems with converting.
    I realise Java doesn't have these functions but I've been fiddling around and looking around the net trying to get a solution. The php is using 'I' as its format mask which is Unsigned Integer so I've used :
    Integer.toBinaryString(toStringInt)
    which should be returning the unsigned integer but I'm having trouble trying to get it back from the binary string.
    When I stick the result of the above code into Integer.parseInt(string, int) it gives me a number format exception
    Can anyone help?
    Thanks

    ok but how do I set the lower 32 bits? And what is setting the highest bit even doing because I have no idea how the server will respond if I don't set it. As I said I'm porting this from PHP which does all of this and doesn't explain why so I don't know what it's doing it for. The PHP is
    function _encodeHeader($isFromServer, $isResonse, $sequence)
         $header = $sequence & 0x3fffffff;
         if($isFromServer)
         $header += 0x80000000;
         if($isResponse)
              $header += 0x40000000;
         return pack('I', $header);
    That is what I'm porting from so that is why I'm setting the highest bit.

  • How to parse 16 bit signed integer

    Currently, I am attempting to collect meaningful data from a flow meter
    connected through serial communication (RS-232 port).  The
    received data is a 16 bit signed integer in two's complement
    representation i.e. the 16 bit signed integer is in binary format with
    2 bytes synchronization  preceding. 
    For each value from the flow meter the byte sequence recevied is as
    follows:  0x7F (sync) , 0x7F (sync) , MSB , LSB.  When
    parsing, I would like to ignore the buffers and store/convert the
    correct values from the flow meter into decimals, but I do not know how
    to do that.  I attempted to use Instrument I/O Assistant and the
    programming similar to it, but I don't know how to identify the buffers
    as seperators. 
    Do any of you know how to do this?  Let me know if you need more information. Your help will be most appreciated. 

    Well, cast the entire string as an array of U32, use "split numbers" to get the last 16 bits each, cast to I16.
    (look ma, no loops! )
    Message Edited by altenbach on 10-12-2005 09:57 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    cast.png ‏3 KB

  • Modbus real to unsigned integer conversion

    Is there any alternative way of decoding the two unsigned integer 16 bit words received through Modbus when using reals? I am using the join numbers and type cast functions; however I am not able to download the complete Modbus list to a compact RIO with 32 MB RAM as it runs out of memory.

    Khalid,
    Thanks for your response. However, let me tell you more about my problem:
    Basically my project consists of:
    1. A list of shared variables within a library that also contains modbus slave with the communication settings.
    2. (5) VIs that used to convert UInt16 to Single (for inputs) and Single to UInt16 (for otputs)
    3. (1) VI to display information
    As I try to download into a cRIO-9002 with 32MB of RAM, the device drops the communication and goes into safe mode, blinking the STATUS light 4 times, this means "run out of memory" .
    I would like to know if there is any other alternative way to overcome this problem. Join and cast is functionally correct but it uses too much RAM

  • Number to a binary base number

    How can I convert a numeric data to a binary base number?
    Ex.: A into 0001010
    Thank you in advance

    OK, only conversion to a string is needed to solve the problem. (Everything else is just a cosmetic feature of the indicator where you set the formatting. This does not change the underlying data.)
    Just use "format into string" with a format code of "%07b" (=show seven binary digits and pad with zeroes to the left).
    LabVIEW Champion . Do more with less code and in less time .

  • Converting from unsigned int / short to byte[]

    Can anybody help me, I am trying to convert from:
    - unsigned int to byte[]
    - unsigned short to byte[]
    I will appreciate your help lots. thanks.

    @Op.
    This code converts an integer to a byte[], but you have to consider the byte order:
            int value = 0x12345678;
            byte[] result = new byte[4];
            for (int i=3; i>=0; i--) {
                result[i] = (byte)(value & 0xff);
                value = value >> 8;
            }This is another option:
            int dummy = 7;
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            os.write(dummy);
            byte[] bytes = os.toByteArray();Kaj

  • 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

  • Unsigned integer problem

    Hi,
    I have a problem of converting a CRand32 function from C to Java which was originally from IDA decompiler.
    There's one thing that's troubling me for quite a long time which is the lack of unsigned types, I could not do operations such as byte shifting correctly and the end result I get is sometimes a negative number or larger than 4billion.
    This CRand function should only generate 0 ~ 4billion.
    Can anyone enlighten me in this? As it's the first time I am doing such things.
    Here's the code I have from direct translation from C to Java :
        private transient long seed1, seed2, seed3; // In the code this is an unsigned int_32
        public final long CRand32__Random() {
         // assume the seed is already an unsigned long..
         seed1 = ((seed1 & 0xFFFFFFFE) << 12) ^
              (((seed1 << 13) ^ seed1) >> 19);
         seed2 = ((seed2 & 0xFFFFFFF8) << 4) ^
              (((seed2 << 2) ^ seed2) >> 25);
         seed3 = ((seed3 & 0xFFFFFFF0) << 17) ^
              (((seed3 << 3) ^ seed3) >> 11);
         return (seed1 ^ seed2 ^ seed3);
        }Thanks,
    Edited by: LightPepsi on May 30, 2010 11:40 PM
    Edited by: LightPepsi on May 30, 2010 11:40 PM

    LightPepsi wrote:
    That was the first thing which comes to my mind by changing >> to >>>, however the numbers generated are usually not within the range of an unsigned integer.
    It can be sometimes a negative number or larger than 4 billion and thus making the randomizer inaccurate.One possibility is to use ints for the internal shifts, but create a long as
    long unsignedValue = intValue & 0xFFFFFFFFL;for returning the number and possibly for any internal comparisons you need to make.
    Winston

  • Audio Digital Analog Converter bit resolution

    Hello ! i´m looking if I can use IPHONE to make my investigation project. Someone of you know which is the audio Digital Analog Converter bit resolution for a normal audio conversation? 13bits? thank you very much

    MonoPrice.com has a digital to analog converter for around $25 although it looks like it is on back order. I would give them a call anyways. Don't get fooled by their prices, they are fast and cheap but good and the place to buy all your audio and video cables. I wired up my sisters entire home theater for less than a quarter of what I payed for my first HDMI cable which I didn't pay much for either.
    http://www.monoprice.com/products/product.asp?cid=104&cp_id=10423&cs_id=1042302&pid=6884&seq=1&format=2

  • How to scale 32-bit signed integer data to floating-p​oint voltage when acquring data in DAQmx by PXI4472?

    I acquired data in DAQmx by PXI4472. For the high speed data logger, I used "DAQmx Read" to read unscaled 32-bit signed integer data.
    Now, my question is how to scale 32-bit signed integer data to floating-point voltage?
    I think that it's (20/(2**24))*I32 because the voltage range of PXI4472 is -10 to +10 and its resolution is 24 bits. But I cann't get correct voltage by that formula.

    While you could hard code the scaling factor, it will be more flexible if you retrieve the scaling coefficients from the driver. To do this, you need to use the Analog Input>>General Properties>>Advanced>>Device Scaling Coefficients>>Device Scaling Coefficients properties under the DAQmx Channel Property Node. Look at the documentation for this property to see how it can be used to create a polynomial equation for scaling to volts.
    Since you are creating a data logging solution, you may want to consider using a compressed data stream from the driver instead of the I32 data type. This will allow you to read the data back as a stream of u8's instead. Since the PXI-4472 is 24 bits, you will only have to write 3 bytes to disk for each sample instead of 4. You can check out the following examples for how to create an application using this compressed data stream. It also shows how to use the scaling coefficients to transform the unscaled data back to voltage values.

  • Convert float to integer

    how to convert float to integer?
    and convert it back from integer to float?

    You can cast a float to an integer using the following syntax:
    float f = 1.245;
    int i = (int)f;
    To convert an int to a float you use a similar syntax:
    int i = 3;
    float f = (float)i;
    You'll also find some interesting methods for the Float and Integer object s in the Java API documentation.

  • Photoshop CS4 - Converting bit depth on import

    Photoshop seems to be converting pictures that I open to 8-bit from 24-bit: before the problem I think it was converting to 16-bit because Photoshop doesnt seem to support 24-bit but I cant remember.
    I've been using Photoshop CS4 for about 4-5 weeks now without any problems and this just seems to have come out nowhere. The problem doesn't seem to be related to Camera Raw at all because I don't use it to import my pictures, so the "Workflow Options" don't seem to have any effect on the converting. I've also tried to delete the preferences file and that doesn't help either.
    Any ideas?

    Photoshop doesn't convert bit depths or color modes when opening documents, unless there is an unsupported bit depth (like 12 bits/channel) in which case we convert upward (to 16 bits/channel).
    It would help if you told us what file format you were talking about, and what you mean by "24 bit".

  • How to return array of unsigned integer pointer from call library function node & store the data in array in labview

    I want to return array of unsigned integer from call library node.
    If anybody knows please help me
    Thanks & Regards,
    Harish. G.

    Did you take a look at the example that ships with LabVIEW that shows how to do all sorts of data passing to DLLs. I believe your situation is one of the examples listed. You can find the example VI in the "<LabVIEW install directory>\examples\dll\data passing" directory.

Maybe you are looking for

  • Launching Edge code thru terminal for Ruby on Rails

    hello i am studying ruby on rails programming.  i just started and I am new to alot things about it. The tutorials im watching say to use sublime text or some other one.  if it makes sense i would like to use edge code because i come from a design ba

  • Creation of PR with MD01

    Hi, Somebody knows if exists some parameter that allows the grouping creation of PR with transaction MD01? In my customer, the MD01 creates one PR for each material Thank you!

  • Can someone recommend a Mini Displayport Female to HDMI cord/adapter?

    I would like to get an Apple 27" to use with my PC, which has both HDMI and DVI inputs. Thanks!

  • Balance Carryfoward Function Using FOX

    Hi ,   I got to create a FOX function to do (BCF) Balance Carryforward .. i need to COPY some records from one version(P6),Fiscal Year(2008) to another version(P1) and fiscal year(2009).While doin so i also need to carryforward the Previous years Bal

  • Portal language from URL

    Hi, Is it possible to force the portal to be displayed in a specific language based on an attribute passed by URL? We are on NW04S SP 10. Is there any other way to force the portal to be displayed in a specific language other than the browser setting