From 3d0c3a9660c78c960675d9139e66497c0d823023 Mon Sep 17 00:00:00 2001 From: Ashutosh Pandey Date: Tue, 23 Jun 2020 19:41:11 +0530 Subject: [PATCH] Added example code/Notes and warnings Code was tested on Arduino Mega 2560 --- .../Functions/Bits and Bytes/bitRead.adoc | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Language/Functions/Bits and Bytes/bitRead.adoc b/Language/Functions/Bits and Bytes/bitRead.adoc index b6c324c15..6cd640b31 100644 --- a/Language/Functions/Bits and Bytes/bitRead.adoc +++ b/Language/Functions/Bits and Bytes/bitRead.adoc @@ -38,7 +38,31 @@ The value of the bit (0 or 1). -- // OVERVIEW SECTION ENDS +=== Example Code +// Describe what the example code is all about and add relevant code +Reads the bit at the specified position and returns the value. In this example the binary representation of 6 is 0110, since `n=1` the value of the second bit from the right (which is 1 in this case) will be read and printed. +[source,arduino] +---- +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + int x = 6; int n = 1; //setting the value of x and n + Serial.print(bitRead(x,n)); //reading the bit at position n and printing the value +} +---- +[%hardbreaks] + +[float] +=== Notes and Warnings +The indexing of the rightmost bit starts from 0, so `n=1` reads the second bit from the right. +Both `x` and `n` must be integer type. + +-- // SEE ALSO SECTION [#see_also]