c++ - Need to change a string to binary, then to ASCII -


I have some data from the sensor, the data is in the range of a signed int, 16 bit or more. I need to send data via Bluetooth.

Problem:

The data is -1564, say. Bluetooth transmit - 1, 5, 6, then 4. It is disabled; I can process data on PC later, I just need frequency to go.

My Idea / Solution:

It has been changed to binary, then for ASCII for output. I can change ASCII later in processing. I have a binary share (found on stack overflow):

  Inline Zero printbinderpad (four c) {for (int i = 7; i> = 0; -i) { Turtle ((C and (1  i)) '1': '0'); }}  

These outputs are very good in binary. But ask to transmit Bluetooth, 24, 1, 1, 0, 0, then zero turns out. In fact, slower than just 2, then 4.

Say I have 65062, 5 bytes for communication, coming out of the sensor, it is 1111111000100110 in binary, 16 bytes for ASCII, this & amp; (Yes, the set character here is small, I know, but it is unique) just 2 bytes! The EFs in Hex are 26, 4 bytes. 3 vs decimal save and 14 versus binary and 2 vs hex is fine, obviously, I want ASCII to be sent here.

My question:

So, if I give binary input then how do I change to ASCII? I would like to send it, ASCII

Hedging:

Yes, more than C ++ code in Matt Lab is a BAUD 115200 for this microcontroller. No, I do not know how the code above works, I do not know where the documents of the Puster are found. If you need to run it, then tell me, as I do not know.

Thanks for any further help or advice, I appreciate it.

Edit: In response to some comments: I'm reading this with two 16 bit registers, so data loss is impossible

, which is usually the console

You can see other output functions in the library.

Anyway, using a putchar () , here's a way to get what you are asking for:

  Zero print_bytes (int n) {four * p = (four *) & amp; N; For (size_t i = 0; i  

If you are certain that you want only 16 bits from integer, you can simplify it like this:

  zero print_bytes ( Int n) {char b = n & amp; 0xff; Four A = (n> 8) & amp; 0xff; Tutor (A); Catechu (B); }  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -