How to convert a negative "signed short int" in a picture of two "tank"?

Hello

I'm having difficulties to convert a signed short int (2 byte) in an array of two characters.

My current test is like this:

void ConvertShortIntToByteArray(short int value){   unsigned char byteHi = 0x00; // High Byte of result   unsigned char byteLo =0x00; // Low Byte of result

  unsigned char C1 = 0x00;  unsigned char C2 = 0x00;  unsigned char C3 = 0x00;  unsigned char C4 = 0x00;  short int tempValue = 0;

    C4 = value % 16;  tempValue = value / 16;   C3 = tempValue % 16;  tempValue /= 16;  C2 = tempValue % 16;  tempValue /= 16;  C1 = tempValue % 16;

  byteHi = C1 << 4;   byteHi += C2;

  byteLo = C3 << 4;   byteLo += C4;}

It works OK for positive values (for example say that 240 = 0 x 00 F0) but negative values don't work here.

Is there a way to convert signed short int values to an array of two bytes of an easier way?

I know that common sense would be to go over binary like this:

Assume value = -240:

So abs(-240) = 240 = 00 F0 = 0000 0000 1111 0000

One-Complement:1111 1111 0000 1111

Add '1' to the One-Complement: 1111 1111 0000 1111+0000 0000 0000 0001  ------------------- 1111 1111 0001 0000

Result = 1111 1111 0001 0000 = FF 10 = -240

But is there an easier way that doesn't have to go to binary to achieve?

Any help is greatly appreciated.

Thank you and best regards,

Bernd

If you want to just let C do its thing:

void ConvertShortIntToByteArray(short int value)
{
    unsigned char byteHi = value >> 8; // High Byte of result
    unsigned char byteLo = value; // Low Byte of result
}

Or maybe a little more understandable:

void ConvertShortIntToByteArray(short int value)
{
    unsigned char byteHi = (value >> 8) & 0xff; // High Byte of result
    unsigned char byteLo = value & 0xff; // Low Byte of result
}

Tags: NI Software

Similar Questions

  • How to convert a PDF file that contains an image (picture) with added text typewriter (numbers next to faces) in a JPEG file?

    I'm trying to convert a PDF to JPEG.  The PDF file contains a picture JPG (photo of a group of people) which I added text (numbers next to each face) using the Acrobat typewriter function.  When I use Save as and select JPEG saved file does not contain the added text.  I tried to export the file and got the same results.  Is it possible to save the PDF modified with the addition of text to a new JPEG file?

    Hi jackh46691612,

    Simply fill out the PDF using the Adobe PDF printer, make sure that you have selected "Document & annotations" in the dialog box to print before printing to the Adobe PDF printer.

    Kind regards

    Nicos

  • How to convert int to String

    How to convert int to String. I get the error 'cannot convert integer to int.

    Dim str As String = "abc";

    int NB = Integer.valueOf (str);

    Use Integar.parseInt (). But make sure your str contains the integer value (like str = '123') otherwise you will get the exception.

    String str = "123"; int num = Integer.parseInt(str);
    

    Concerning

    Bika

  • How can I convert a negative image of the film a positive image in Lightroom 6?

    I've seen a number of online tutorials that explains how you can reverse/return line in the Module development of tone curve by dragging either end of the line, top / bottom for converting a negative to a positive image. This however does not seem possible in LR 6?  So, how are you? (My scanner is able to produce positives TIFF or JPEG of the film I've been scanning, but I would have preferred to edit pictures using Raw DNG files that it produces, which are negative).

    You must click on the small icon in the lower right curved panel to make editing possible.

    If it comes to color film, I don't know how good a conversion that would be, it will certainly color adjustments, because of the orange mask in the negative.

    And a scanner DNG files? I doubt that they will be real raw files...

    You can scan an image tiff with all the cliches and to highlight the present details, and that will be as good as any raw file.

  • OpenScript/Bank of data/how to convert string to int

    Hello

    As far as I know, the values read from the database is a type of Sting. Now, I want to convert a character number stored in the database of type int.
    For example, in "Test.csv" I stored the '9' in the column 'Number' character, then I use the following code to read the character and convert an int in one:
    getDatabank("Test").getNextDatabankRecord ();
    String Testnumber = "{{db." Test.Numberr}} '; Info (Testnumber);
    int number = Integer.parseInt (Testnumber);

    However, it seems this does not work, because he says "basic unexpected failure caused by: NumberFormatException occurred." For the input string: «{{db.» Test.Numberr}}.
    I think that this error can be caused by the conversion of character '9' int 9.
    Can someone tell me how to convert a character to be read from database in an int?

    Thank you very much!

    Kind regards
    Angyoung

    Hello

    You can use the same approach. Use eval()

    getDatabank("Test").getNextDatabankRecord();
    String Testnumber =eval("{{db.Test.Numberr}}") ;
    info(Testnumber);
    int number = Integer.parseInt(Testnumber);
    

    Kind regards
    Dembélé M

  • Whole ContextProperty or how to convert an int in QObject

    How QObject can be created from an int value?

    I need to set the whole context property.

    Thanks in advance,

    Eugene

    Sorry, I already found the answer.

    In this case, it must explicitly use QDeclarativeContext.

    for example

    int integerValue = 42;
    QVariant qIntegerValue(integerValue);
    QDeclarativeContext* context = |instantiate new or use exist|;
    context->setContextProperty("intValue", qIntegerValue);
    
    QmlDocument* doc = QmlDocument::create("you.qml");
    Page* page = doc->createRootObject(context);
    
  • How to read the entire signed in the Modbus IO Server 16-bit register

    HI, I'm using Labview 2011. I like read 16 bit holding register to another PC using Modbus.But option is there only to read "registry of operating as 16-bit integers from 0 to 65 535".

     

    "But how to interpret as signed integers, as some registry values can have negative values". If the reading as unsigned integers, values is false. Is there a way to convert unsigned to signed integers integers.

     

    concerning

    Ahmed Tafesh

    Yes, you can do the conversion... just be careful to not change its value or to complete something you need in the conversion process.

    Since the block diagram, range of functions-> programming-> Digital-> Conversion

    Try the I16 or the FXP. The I16 is a direct conversion, so you can't really control how it gets converted. The FXP you can right click and select properties to make the conversions.

    If all else fails, you can do the U16 to binary to FXP to I16. It may be the long way to get there, but it should work.

    R ^ 2 (Ryan)

  • How to convert times from second to hh with CVI

    How to convert times from second to hh with CVI?

    Can anyone advice?

    It's here. As I told you, it's very simple:

    //----------------------------------------------------------------------
    // Function secToHMSstring ()
    //----------------------------------------------------------------------
    /// HIFN secToHMSstring ()
    /// HIFN The function takes an amount of seconds and returns a string with
    /// HIFN the corresponding value in H:M:S format
    /// HIPAR sec/Value in seconds to convert
    /// HIPAR verbose/If True use "hms" separators; if not, use ":" separator
    /// HIPAR string/The output string. It is responsibility of the programmer
    /// HIPAR string/that the string is large enough to keep the resulting text
    /// OUT string
    void secToHMSstring (int sec, int verbose, char *string)
    
    {
        int     hh = 0, mm = 0, ss = 0;
    
        if (sec >= 3600) {
            hh = sec / 3600;
            sec -= hh * 3600;
        }
        if (sec >= 60)
            mm = sec / 60;
        ss = sec - mm * 60;
    
        strcpy (string, "");
        if (verbose) {
            if (hh > 0) sprintf (string, "%s%dh", string, hh);
            if (mm > 0) { if (strlen (string)) strcat (string, " "); sprintf (string, "%s%dm", string, mm); }
            if (ss > 0) { if (strlen (string)) strcat (string, " "); sprintf (string, "%s%ds", string, ss); }
        }
        else {
            if (hh > 0) sprintf (string, "%s%d:", string, hh);
            if (mm > 0) {
                if (strlen (string)) sprintf (string, "%s%02d:", string, mm); else sprintf (string, "%d:", mm);
            }
            else if (strlen (string))
                strcat (string, "00:");
            if (strlen (string)) sprintf (string, "%s%02d",  string, ss); else sprintf (string, "%d", ss);
        }
    
        return;
    }
    
  • How to convert wordpress theme to Blogger in Dreamveawer?

    I have a site on [private info removed by Moderator], it's in wordpress I'm was thinking create the same in blogger, but I don't know where to start and how to convert, I know that there could be a way that is really hard, and that is if I start coding in full to new , but is there anyone who can tell me a solution so that I can change it in a short time a simple way...

    Blogger Templates are completely different WordPress themes.  It's like apples and oranges.

    Best advice, find a Blogger template you like (commercial or free).

    Blogger templates gallery

    http://designscrazed.org/best-free-Blogger-templates/

    Proactive and the reactive Blogger templates 2015

    http://www.pipdig.co/

    Nancy O.

  • How to convert pdf to word document

    How to convert pdf to word document

    Hi chrish29712807

    You can install Adobe Acrobat Reader DC Acrobat Reader DC Learn & support, sign in using your Adobe ID, in which you have membership of the Adobe PDF package & then follow the steps in this KB document using Acrobat Reader. Export PDF to Acrobat Reader DC to export PDF files.

    You can also use this service online at https://cloud.acrobat.com/exportpdf

    Kind regards

    Nicos

  • my upgrade to 2015 shows how how to convert trial to licensed version?

    I recently opened my creative Cloud 2014 version window and the screen is blank. I finally fixed this problem, but after being able to see my apps it says install 2015.  I did it and now they are all versions of trail.

    How to convert these versions to test for my licensed version?

    Check that your account is up to date, Adobe ID

    Then, if it's current, disconnect and then back to your client application to cc using the same adobe id used with the link above: http://helpx.adobe.com/creative-cloud/kb/sign-in-out-creative-cloud-desktop-app.html

  • How to convert pdf to publisher file

    Any suggestions on how to convert a PDF into a publisher file?  I use a trial version of adobe acrobat pro 11.

    The short answer is you can't.

    It is possible to export to Word and then rebuild the document by hand, but it's not really simple.

  • How to convert a PDF with handwritten signature?

    How to convert a PDF with handwritten signature?

    Hi Lotus1215,

    Once the document is signed this document, we can edit, where the conversion is not possible

    Please see the article mentioned below

    http://forums.Adobe.com/docs/doc-1515

    I would like to know if you have any further questions.

    Kind regards

    ~ Dominique

  • How to keep the cursor in short to a TLF in ScrollPane?

    How to keep the cursor in short to a TLF in ScrollPane? Consider this:

    textFlow.addEventListener (UpdateCompleteEvent.UPDATE_COMPLETE, tlfUpdtHandler, false, 0, true);


    private void tlfUpdtHandler(e:Event):void {}
    textFlow var = e.currentTarget;
    var containerController = textFlow.flowComposer.getControllerAt (0) as ContainerController;
    var contentBounds:Rectangle = containerController.getContentBounds ();
    var tlf_mc = containerController.container;
    containerController.setCompositionSize (containerController.compositionWidth, contentBounds.height);
    var sp:ScrollPane = tlf_mc.parent.parent;
    TPI Update();
    trace (Math.ceil (SP.verticalScrollPosition), Math.ceil (sp.maxVerticalScrollPosition), sp.verticalScrollPosition, sp.maxVerticalScrollPosition);

    sp.verticalScrollPosition = sp.maxVerticalScrollPosition;

    }

    I can't do this as the scroll position will always be in the last line. I would like the scrollpane to scroll to the line where the content is typed.

    Kindly help out me with pointers.

    Thank you.

    Sabine

    Thanks I understand now.  I'm not familiar with the fl classes but here goes.

    (1) using the NaN being the height of composition that tlfUpdateHandler keeps the cursor in view.  It worked with a few simple tests - there may be a few missing details.  I call sp.update so that it catches the total height changes?

    private void tlfUpdtHandler(e:UpdateCompleteEvent):void
    {
    find the current activePosition
    var activePos:int = e.textFlow.interactionManager.activePosition;
    If (activePos == - 1).
    return;
               
    var tfl:TextFlowLine = e.textFlow.flowComposer.getLineAt (e.textFlow.flowComposer.findLineIndexAtPosition (os activeP));
               
    If his view not to scroll into view
    If (sp.verticalScrollPosition > tfl.y: sp.verticalScrollPosition + sp.height)<>
    sp.verticalScrollPosition = tfl.y - 20;    just a number for him give a certain margin above
    }

    (2) If you do not use NaN as the height of the composition (less accurate but works better) I don't think that you will be able to use ScrollPane.  TLF automatically scrolls the lines inside the Sprite using the limits of composition.  Instead, you need to instantiate a control ScrollBar and synchronize the contentBounds with maximum heights and also synchronize the scroll positions.  TLF generates a "scroll" event every time it scrolls the content.  ContainerController has a r/w for verticalScrollPosition properties.

    Hope that helps

    Richard

  • How to convert pictures from iPhoto?  I need general info and advice.  My library is huge (95 GB).  I am running OSX El Capitan 10.11.6 on iMac.

    How to convert pictures from iPhoto?  I need general info and advice.  I saw the help info but I am very nervous to take on this project, as my library is huge (95GB), organized in several events and albums.  My library is saved (Time Machine SimpleSave HD).  I am running OSX El Capitan 10.11.6 on iMac.

    Have you seen this document?   Updated Photos for OS X - Apple iPhoto support

    https://support.Apple.com/en-GB/HT204655

    Is your iPhoto Library Library on your system drive in the pictures folder? And you have a lot of free space on your system drive? The migration will need additional temporary storage.

    Then drag the iPhoto library icon pictures open to create a new library of Photos of her.

    Your albums appear unchanged in the Photos.  Events will appear as additional albums, because the pictures has no events.  See this link: How Photos handles content and metadata for iPhoto and Aperture - Apple Support

Maybe you are looking for