<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/</id><updated>2020-02-27T13:57:04.123000Z</updated><subtitle>Recent posts to Is it possible for a byte to have a negative sign?</subtitle><entry><title>Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/?limit=25#4844" rel="alternate"/><published>2020-02-27T13:57:04.123000Z</published><updated>2020-02-27T13:57:04.123000Z</updated><author><name>dFx</name><uri>https://forge.codesys.com/u/dfx/</uri></author><id>https://forge.codesys.com98e1a426fd8df2e368e2a47dc5478c9d407987b2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;btw, sending a joint angle value coded on a byte seems very low resolution …&lt;br/&gt;
Check your doc about wrong type (byte int or dint) as noted by scott&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/?limit=25#ae13" rel="alternate"/><published>2020-02-27T13:57:03.797000Z</published><updated>2020-02-27T13:57:03.797000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com0e58688a406b0d87d140fa1a1b882c5c363272d7</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;computers represent numbers as bits. As such, negative numbers do not really exist. Instead, both the sender and the receiver agree to use a bit to signal that the number should be treated as a negative value.  It is possible to send a negative value even with the data type as byte.  For example, in modbus, dats is sent as WORDS (0..65535). But if both sides agree that WORD 2 should be a negative, then you can send a number from -32768 to 32767.  It is even possible to have both sides agree that two WORDS in a row can be a REAL number. &lt;/p&gt;
&lt;p&gt;So in your problem, it seems to me that your receiver does not expect a negative value. Or as mentioned before, maybe the receiver is expecting 16 bits as a negative. If that is the case, then -1 has to be sent as 0xFFFF (not 0xFF - because 0xFF is actually 0x00FF, a positive number).  Check your documentation on the receiver of your data.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/?limit=25#5ea2" rel="alternate"/><published>2020-02-27T13:57:02.982000Z</published><updated>2020-02-27T13:57:02.982000Z</updated><author><name>Carlos Barría</name><uri>https://forge.codesys.com/u/carlos-barria/</uri></author><id>https://forge.codesys.comc57ab6f2b669c66648ab24dc0ea7d40ee4f8915c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;It is not clear to me.  that the value 255 in byte is interpreted as -1 (negative value) in my controller? Use a raspberry as a controlling device&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/?limit=25#6846" rel="alternate"/><published>2020-02-27T13:57:02.643000Z</published><updated>2020-02-27T13:57:02.643000Z</updated><author><name>Carlos Barría</name><uri>https://forge.codesys.com/u/carlos-barria/</uri></author><id>https://forge.codesys.combaa73f2c3b6e31b2412995aa566b8d8ce5352f31</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;I-Campbell hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Sending byte value 255 is correct if you want to send -1.&lt;br/&gt;
What is your receiving device? Your receiving device needs to interpret 0xFF as -1.&lt;br/&gt;
Is it even expecting an 8 bit value? If it's expecting more, you might need 0xFF.&lt;br/&gt;
The best we to display the same bits as different interpretations is with a DUT UNION.&lt;/p&gt;
&lt;/blockquote&gt;&lt;/div&gt;</summary></entry><entry><title>Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/?limit=25#b0ee" rel="alternate"/><published>2020-02-27T13:57:02.275000Z</published><updated>2020-02-27T13:57:02.275000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.combcfaf780aaaf98c68dda1711c0a09930cca09987</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Sending byte value 255 is correct if you want to send -1.&lt;br/&gt;
What is your receiving device? Your receiving device needs to interpret 0xFF as -1.&lt;br/&gt;
Is it even expecting an 8 bit value? If it's expecting more, you might need 0xFF.&lt;br/&gt;
The best we to display the same bits as different interpretations is with a DUT UNION.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/?limit=25#de9b" rel="alternate"/><published>2020-02-27T13:57:02.011000Z</published><updated>2020-02-27T13:57:02.011000Z</updated><author><name>Carlos Barría</name><uri>https://forge.codesys.com/u/carlos-barria/</uri></author><id>https://forge.codesys.com78e09483c48c43e554b89bd3db899d9f4eca9f4f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;dFx hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
sign is just an interpretation of the binary data. Usually, the sign is the most significant bit in your data.&lt;br/&gt;
in your case, using a byte, means 8 bits of data. Max unsigned range is 0~255. But if you interpret it as signed then range is -128~127.&lt;br/&gt;
so it is just a different method in evaluating the value that causes your problem.&lt;br/&gt;
so your solution may be in correcting how you evaluate it.&lt;br/&gt;
Why do you need to send some negative values ?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I need to send messages that contain joint angle values, therefore it is necessary to send some negative angles. I have tried changing the variable to SINT, but it does not recognize the sign.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/?limit=25#bf82" rel="alternate"/><published>2020-02-27T13:57:01.794000Z</published><updated>2020-02-27T13:57:01.794000Z</updated><author><name>dFx</name><uri>https://forge.codesys.com/u/dfx/</uri></author><id>https://forge.codesys.com546bfecb006e21326cbffc1cdc1ea3ee4b6819a9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;sign is just an interpretation of the binary data. Usually, the sign is the most significant bit in your data.&lt;br/&gt;
in your case, using a byte, means 8 bits of data. Max unsigned range is 0~255. But if you interpret it as signed then range is -128~127.&lt;/p&gt;
&lt;p&gt;so it is just a different method in evaluating the value that causes your problem.&lt;/p&gt;
&lt;p&gt;so your solution may be in correcting how you evaluate it.&lt;/p&gt;
&lt;p&gt;Why do you need to send some negative values ?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Is it possible for a byte to have a negative sign?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/a6db2aa3f8/?limit=25#8965" rel="alternate"/><published>2020-02-27T13:57:01.053000Z</published><updated>2020-02-27T13:57:01.053000Z</updated><author><name>Carlos Barría</name><uri>https://forge.codesys.com/u/carlos-barria/</uri></author><id>https://forge.codesys.com63ddd25ff8506c831a4c552a31d36a8e8af95397</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I am working with the CAN API library and I need to send negative data but the negative data converts them to positive. How can I send negative bytes?. &lt;br/&gt;
For example I send a byte -1 and the program converts it to 255&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>