aboutsummaryrefslogtreecommitdiffstats
path: root/source/arduino/bytecast.rst
diff options
context:
space:
mode:
Diffstat (limited to 'source/arduino/bytecast.rst')
-rw-r--r--source/arduino/bytecast.rst35
1 files changed, 22 insertions, 13 deletions
diff --git a/source/arduino/bytecast.rst b/source/arduino/bytecast.rst
index 71ab4aa..bf85a35 100644
--- a/source/arduino/bytecast.rst
+++ b/source/arduino/bytecast.rst
@@ -1,41 +1,50 @@
+.. highlight:: cpp
+
.. _arduino-bytecast:
-byte()
-======
+byte() (cast)
+=============
Description
-----------
-Converts a value to the
-`byte <http://arduino.cc/en/Reference/Byte>`_ data type.
+Converts a value to the :ref:`byte <arduino-byte>` data type.
+
+.. warning::
+ Casting to the byte type is provided for compatibility with
+ Arduino. However, ``byte`` is a non-standard type. The standard
+ C++ type for storing an 8-bit unsigned integer is ``unsigned
+ char``, and we recommend using that instead.
+ In order to cast a variable ``x`` to an ``unsigned char``, the
+ following syntax can be used::
+
+ (unsigned char)(x);
Syntax
------
-byte(x)
-
+``byte(x)``
Parameters
----------
-x: a value of any type
-
+**x**: a value of any integer type
Returns
-------
-byte
-
+The value, converted to a ``byte``. Note, however, that if the value
+is larger than the maximum value you can store in a byte (255), then
+the results might be strange and unexpected.
-See also
+See Also
--------
-
-- `byte <http://arduino.cc/en/Reference/Byte>`_
+- :ref:`arduino-byte`