5
votes
Set and extract individual bytes of a number (lowByte() and highByte())
Any more sophisticated byte exchange can be done with binary operators.
Extracting information
You'll need some constants like
MASK SHIFT
0xFF000000 24 ...
4
votes
Accepted
How 2 bytes can produce negative number, mind blowing?
I won't explain it like you are 5-years old because it would take to
much effort, you are a grown up, and you are capable of reading articles
yourself. So start by putting aside ChatGPT, and instead ...
3
votes
Accepted
RF24 library commands, channel, and address
A. Does address take character or number as input?
The address is 5 bytes. In this library it is provided as an array. In C a string is merely an array of bytes. So it is possible to represent an ...
3
votes
Accepted
How to modify a created byte?
Well first of all you are trying to name the variable char? which is already a keyword for the variable type of char. But you can access it by the index of the array. Also not sure if you intended ...
2
votes
How to convert char[12] to byte[6]
It is not clear why you are trying to implement it from scratch. If your input is always properly formatted you can perform the conversion in one call to sscanf
char arr[] = "A4BDC334688C";
byte ...
2
votes
Accepted
How to convert char[12] to byte[6]
Please see the comments in the code:
// SDMacAdress is zero terminated
// (it should be because you use strcp not strncp)
// char arr[12]; you need one extra byte for the zero
char arr[13];
strcpy(...
2
votes
How to modify a created byte?
You can use the following array initialization:
In the setup I shows how to set a bit. For this, the bit operator or (|) is used. To reset a bit, you can use &. You can set/reset multiple bits ...
2
votes
USing arrays, binary data and bitRead
There are only two errors I can spot in your program:
A block of code should be delimited by curly braces:
for (count=0; count<8; count++){
pinMode(pinArray[count],OUTPUT);
} // ← ‘}’ instead ...
2
votes
Parse char* mac-string to uint8_t array
Personally I'd go with a basic implementation such as this one.
const uint8_t MAC_length = 6;
uint8_t* MAC_buffer[6];
uint8_t fromHexChar(char c)
{
uint8_t result = 0
if ((c >= '0') &&...
2
votes
Is there a variable type of half byte? Is there a workaround?
If the point is to save program storage space, you're probably going to have to live with some unreadable bit mush or do bit-swapping in your head. Here's a code example that encodes your same array ...
1
vote
Accepted
How to get recover numeric data sent by an Arduino in binary
Arduinos use very standard formats for their internal binary
representations of data:
integers are in two's complement
floats follow the IEEE 754 standard
both are little-endian.
This is the same as ...
1
vote
Changing single bit in byte array
The error occurs, because you try to use the syntax for a 2 dimensional array with a 1 dimensional array (since you have an array of bytes, not bits, and a microcontroller always works with at least ...
1
vote
Accepted
Pass Byte Array to Char and Send to a Separate Arduino
You can change your printArray function to work on provided Print instance:
void printArray(byte output[], Print& serial)
{
for (int i = 0; i < 8; i++)
{
if (output[i] < 0x10)
{
...
1
vote
Arduino Serial Monitor Input 3DES Encryption
#include <DES.h>
DES des;
byte in[8];
String input;
char buf[30];
void setup() {
Serial.begin(9600);
Serial.println("Hello!");
}
void tdesTest() {
byte out[8];
byte key[] = ...
1
vote
Accepted
Arduino Serial Monitor Input 3DES Encryption
From your comments I think I understand what you are after. So, assuming you have read some string into a String object called input and you have an array in[8] to populate you can:
Clear the in[] ...
1
vote
Accepted
Why float and not 16-bit Integer? Mpu6050 with atmega328P
In the instructables code he's using a float because he wants to scale the value to a range of ±2g. The values the accelerometer gives are not the actual values but, like the Arduino's ADC, a ...
1
vote
Why float and not 16-bit Integer? Mpu6050 with atmega328P
We can't know this writer's reasons, but a typical reason why someone might use floats vs. ints is that they prefer not to manage the binary-point location and any possible overflows during the ...
1
vote
Accepted
Is there a variable type of half byte? Is there a workaround?
Keeping your 4-bit values in half-bytes is doable using structs and bitfields. You'll want an access function to separate the "array index" into a byte-index and a nibble selector (the LSb ...
1
vote
Set and extract individual bytes of a number (lowByte() and highByte())
There are two alternative methods, and they can both be easily used "in reverse" as well:
Unions
union byte_extract {
uint32_t ival;
struct {
uint8_t byte_0; // least significant ...
1
vote
Set and extract individual bytes of a number (lowByte() and highByte())
The header Arduino.h defines the macro word(high_byte, low_byte). The
resulting value is an uint16_t.
1
vote
need to compare if a byte is less than 80 hex
The rules of integer arithmetics are tricky in C++. There are rules that
give the type of integer literals:
256 and 200 are of type int, which is the default type for
integer literals. On the Nano, ...
1
vote
need to compare if a byte is less than 80 hex
You said "I defined TA as a float." That doesn't matter. In C/C++, expressions are only "promoted" to a larger/different data type AFTER they are evaluated. Your calculations are being done using 16-...
1
vote
Arduino will not read three successive packets in the serial connection
The problem is that your code works but you substract 48 from what you received.
Which if python sends a char with values: '0' '1' '2' it will result in the serially outputted values of NUL SOH STX ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bytes × 18serial × 4
arduino-nano × 4
bit × 4
arduino-uno × 3
array × 3
convert × 3
softwareserial × 2
esp8266 × 1
arduino-ide × 1
sensors × 1
c++ × 1
lcd × 1
string × 1
nrf24l01+ × 1
mpu6050 × 1
arduino-micro × 1
python × 1
wireless × 1
code-optimization × 1
data-type × 1
pointer × 1
rs485 × 1
modbus × 1
functions × 1