Answers.Body: <p>The <code>LC0()</code> macro treats the value as a signed 6-bit integer.</p>
  
  <p>From <a href="https://github.com/mindboards/ev3sources/blob/master/lms2012/lms2012/source/bytecodes.h" rel="nofollow noreferrer">bytecodes.h</a>...</p>
  
  <pre><code>#define PRIMPAR_CONST_SIGN 0x20
  #define PRIMPAR_VALUE 0x3F
  </code></pre>
  
  <p><code>PRIMPAR_VALUE</code> is where the 6 bits come from. <code>PRIMPAR_CONST_SIGN</code> means that the 6th bit is the sign. This means it has a range of -32 to 31, inclusive.</p>
  
  <p>We must also keep in mind that computers use the <a href="https://en.wikipedia.org/wiki/Two%27s_complement" rel="nofollow noreferrer">2's complement</a> for negative integer values, so we can't just use <code>0x34</code> (<code>0x20 | 0x14</code>) and expect it to be -20.</p>
  
  <p><code>0x20</code> will be -32, which is the lowest number possible. So, to get -20, we would need -32 + 12 = -20. In 6-bit hex <code>0x20 + 0x0c = 0x2c</code>. But, you don't actually <em>have</em> to use hex formatted number. We can let the compiler figure it out like this: <code>(-20 &amp; PRIMPAR_VALUE)</code>. This trims the number -20 down to 6 bits. In fact, this is what the <code>LC0()</code> macro does internally, so we can just write <code>LC0(-20)</code>.</p>
  
  <p>If you need values larger than this range (e.g. -100 to 100), then you need to use the <code>LC1()</code> macro, which uses 8-bit signed integers. It has a range of -128 to 127. So, this will work too: <code>LC1(-20)</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-03T18:03:28.680Z
Answers.LastActivityDate: 2018-03-03T18:09:02.350Z
Answers.LastEditDate: 2018-03-03T18:09:02.350Z
Answers.UserDisplayName: David Lechner
Body: <p>I write the java language. I use ev3 direct command make ev3 motor to run, </p>
  
  <p>example:</p>
  
  <pre><code>"opOUTPUT_POWER,LC0(0),LC0(0x01),LC0(20), opOUTPUT_START,LC0(0),LC0(0x01)"
  </code></pre>
  
  <p>In this case, the power is 20 so I write value (byte)0x14 resulted ev3 forward.</p>
  
  <p>When I want to make the ev3 backward, how can I do??</p>
  
  <p>I think change power 20 to -20, but I don't know -20 hex value.</p>
  
Tags: <ev3><software>
Title: How to use the direct command to make EV3 motor backward?
UserDisplayName: aboyo
ThreadText: # How to use the direct command to make EV3 motor backward?
  
  (Asked by: username_0 on 2018-03-03)
  
  I write the java language. I use ev3 direct command make ev3 motor to run, 
  example:
  "opOUTPUT_POWER,LC0(0),LC0(0x01),LC0(20), opOUTPUT_START,LC0(0),LC0(0x01)"
  
  In this case, the power is 20 so I write value (byte)0x14 resulted ev3 forward.
  When I want to make the ev3 backward, how can I do??
  I think change power 20 to -20, but I don't know -20 hex value.
  
  **Tags:** ev3, software
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-03-03. Score: 3 | Accepted answer
  
  The LC0() macro treats the value as a signed 6-bit integer.
  From bytecodes.h...
  #define PRIMPAR_CONST_SIGN 0x20
  #define PRIMPAR_VALUE 0x3F
  
  PRIMPAR_VALUE is where the 6 bits come from. PRIMPAR_CONST_SIGN means that the 6th bit is the sign. This means it has a range of -32 to 31, inclusive.
  We must also keep in mind that computers use the 2's complement for negative integer values, so we can't just use 0x34 (0x20 | 0x14) and expect it to be -20.
  0x20 will be -32, which is the lowest number possible. So, to get -20, we would need -32 + 12 = -20. In 6-bit hex 0x20 + 0x0c = 0x2c. But, you don't actually have to use hex formatted number. We can let the compiler figure it out like this: (-20 & PRIMPAR_VALUE). This trims the number -20 down to 6 bits. In fact, this is what the LC0() macro does internally, so we can just write LC0(-20).
  If you need values larger than this range (e.g. -100 to 100), then you need to use the LC1() macro, which uses 8-bit signed integers. It has a range of -128 to 127. So, this will work too: LC1(-20).
  
  
  ---
  
  