Binary numbers on Raspberry Pi
-
Hello together,
I have been trying for some time now to get my Raspberry PI Project to run but I have not yet found a solution to the following problem:
For the use of the WiringPI SPI Library I need to transmit data - over the SPI - in the format of unsigned chars bytewise. To adress the Register i only have hex or binary values. How can I convert binary or hex values to be unsigned chars so I have the correct type for the parameter to call the function ?
-
Hi,
Can you show what you want to use from the WiringPI library ?
-
@SGaist said:
Hi,
Can you show what you want to use from the WiringPI library ?
Hi,
i want to use the method
int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
where I neet to pass an unsigned char pointer. When I try to set one up like this
unsigned char *data = 0b10000000
I get the warning that conversion from int to unsigned char is not possible.
@vish said:
@Dan90 like this
qFromBigEndian<uint16>((const uchar*) byteArray.data())
this will give u uint16 type from ur bytearray buffer.I understand that this funtion gets an unsigned char and converts it to uint16 ? But as I said, I need an unsigned char in the first place.
-
Then you can use a QByteArray to build your data and then use its data function to access them. You can cast data to unsigned char *
-
Thanks for the hint with QByteArray. I checked it and the problem I still have ist that the data function of my QByteArray object returns a char*, but the wiringPiSPIDataRW function needs an unsigned char*, so I still get an error out of this.
EDIT:
I just tried an explicit type conversion and it worked. Could this have a negative effect on my data by any means ? -
Do a type cast:
wiringPiSPIDataRW (static_cast<unsigned char *>(myByteArray.data()), myBateArry.size());
-