Answers.Body: <p>The NXT actually uses IEEE 794 32-bit floating point number format in little endian byte order. I like using <a href="http://www.h-schmidt.net/FloatConverter/IEEE754.html">this site</a> for conversions.</p>
  
  <p>So, to decode your messages:</p>
  
  <blockquote>
    <p>TX: 00 09 00 05 60 EA 00 00 00</p>
  </blockquote>
  
  <p>Byte 0: 0x00 - response required</p>
  
  <p>Byte 1: 0x09 - write message command</p>
  
  <p>Byte 2: 0x00 - Mailbox 1</p>
  
  <p>Byte 3: 0x05 - Message size of 5 bytes</p>
  
  <p>Bytes 4-7: 0x60 0xEA 0x00 0x00 - since this is little endian, reverse the bytes, 0x0000EA60, which plugged into the conversion site gives us 8.4078E-41</p>
  
  <p>Byte 8: 0x00 - null terminator</p>
  
  <p>Then you add 1.0 on the NXT and return the result.</p>
  
  <blockquote>
    <p>RX: 02 13 00 00 05 00 00 80 3F 00 ... (zeroes)</p>
  </blockquote>
  
  <p>Byte 0: 0x02 - return packet</p>
  
  <p>Byte 1: 0x13 - message read command</p>
  
  <p>Byte 2: 0x00 - success</p>
  
  <p>Byte 3: 0x00 - Mailbox 1</p>
  
  <p>Byte 4: 0x05 - message size of 5 bytes</p>
  
  <p>Bytes 5-8: 0x00 0x00 0x80 0x3F - again, little endian, so reversing bytes gives 0x3F800000 and plugging in to the calculator gives 1.0</p>
  
  <p>Bytes 9-63: 0x00... - padding</p>
  
  <hr>
  
  <p>So, it looks like the NXT is doing exactly what you actually told it (8.4078E-41 + 1.0 = 1.0) rather than what you thought you told it (60000 + 1 = 60001).</p>
  
  <hr>
  
  <p>Plugging 60000.0 into the calculator, it looks like your message should be</p>
  
  <pre><code>TX: 00 09 00 05 00 60 6a 47 00
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-22T01:55:27.863Z
Answers.Text: Thanks! Hours after submitting this question, we searched for "08 3F" and we've found the answer. Anyway, thank you, this specification could be somewhere in the LEGO NXT documentation (at least we didn't find it)
Answers.UserDisplayName: Cristian Porto
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-19T01:31:14.110Z
Answers.LastActivityDate: 2015-04-19T01:31:14.110Z
Answers.UserDisplayName: David Lechner
Body: <p>We've been following <a href="http://www.codeproject.com/Articles/18857/Communicating-with-LEGO-NXT-via-Bluetooth-in-C" rel="nofollow">this</a> tutorial to connect a NXT 1.0 brick to a PC via Bluetooth.</p>
  
  <p>We've been able to set up the communication, send and receive data in ASCII format.</p>
  
  <p>However, whenever we try to send an integer and use it for calculations, it returns the wrong result.</p>
  
  <p>For example, sending 60000:</p>
  
  <pre><code>TX: 00 09 00 05 60 EA 00 00 00
  
  RX: 02 09 00
  </code></pre>
  
  <p>After adding 1, it returns the following:</p>
  
  <pre><code>TX: 00 13 0A 00 01
  
  RX: 02 13 00 00 05 00 00 80 3F 00 ... (zeroes)
  </code></pre>
  
  <p>We've tried sending different numbers, but they all return the same value.</p>
  
  <p>The NXT-G software is identical to that in the tutorial.</p>
  
  <p>How does NXT-G handle the integer data type?</p>
  
Tags: <nxt><software><bluetooth><nxt-g>
Title: What is NXT-G number format?
UserDisplayName: Cristian Porto
ThreadText: # What is NXT-G number format?
  
  (Asked by: username_0 on 2015-04-18)
  
  We've been following this tutorial to connect a NXT 1.0 brick to a PC via Bluetooth.
  We've been able to set up the communication, send and receive data in ASCII format.
  However, whenever we try to send an integer and use it for calculations, it returns the wrong result.
  For example, sending 60000:
  TX: 00 09 00 05 60 EA 00 00 00
  
  RX: 02 09 00
  
  After adding 1, it returns the following:
  TX: 00 13 0A 00 01
  
  RX: 02 13 00 00 05 00 00 80 3F 00 ... (zeroes)
  
  We've tried sending different numbers, but they all return the same value.
  The NXT-G software is identical to that in the tutorial.
  How does NXT-G handle the integer data type?
  
  **Tags:** nxt, software, bluetooth, nxt-g
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-19. Score: 5 | Accepted answer
  
  The NXT actually uses IEEE 794 32-bit floating point number format in little endian byte order. I like using this site for conversions.
  So, to decode your messages:
  
  TX: 00 09 00 05 60 EA 00 00 00
  
  Byte 0: 0x00 - response required
  Byte 1: 0x09 - write message command
  Byte 2: 0x00 - Mailbox 1
  Byte 3: 0x05 - Message size of 5 bytes
  Bytes 4-7: 0x60 0xEA 0x00 0x00 - since this is little endian, reverse the bytes, 0x0000EA60, which plugged into the conversion site gives us 8.4078E-41
  Byte 8: 0x00 - null terminator
  Then you add 1.0 on the NXT and return the result.
  
  RX: 02 13 00 00 05 00 00 80 3F 00 ... (zeroes)
  
  Byte 0: 0x02 - return packet
  Byte 1: 0x13 - message read command
  Byte 2: 0x00 - success
  Byte 3: 0x00 - Mailbox 1
  Byte 4: 0x05 - message size of 5 bytes
  Bytes 5-8: 0x00 0x00 0x80 0x3F - again, little endian, so reversing bytes gives 0x3F800000 and plugging in to the calculator gives 1.0
  Bytes 9-63: 0x00... - padding
  
  So, it looks like the NXT is doing exactly what you actually told it (8.4078E-41 + 1.0 = 1.0) rather than what you thought you told it (60000 + 1 = 60001).
  
  Plugging 60000.0 into the calculator, it looks like your message should be
  TX: 00 09 00 05 00 60 6a 47 00
  
  > **Comments:**
  > **username_0**: Thanks! Hours after submitting this question, we searched for "08 3F" and we've found the answer. Anyway, thank you, this specification could be somewhere in the LEGO NXT documentation (at least we didn't find it)  
  
  ---
  
  