Hello
I worked on a program that converts character and numbers tobinairy format, but when I give him two numbers, for example, 78 does not give me their value in the binary 0100 1110
It only gives it to me as 7 and 8
0011011100111000
how can i fix the prlm?
Collect the complete decimal number from the serial console
Yes.
@light__fidelity, ask yourself how the program knows that the 7 you enter is going to be the 10's digit in a two digit decimal number or the thousands digit in a 4 digit decimal number, or the ones digit in a one digit decimal number?
Your entire approach with the Strings would be better replaced with the character array techniques presented in Robin2's tutorial on Serial Input Basics
cattledog: @light__fidelity, ask yourself how the program knows that the 7 you enter is going to be the 10's digit in a two digit decimal number or the thousands digit in a 4 digit decimal number, or the ones digit in a one digit decimal number?
I'd first ask why one wants / needs an ASCII string representing the value of a variable expressed in binary.
Could be an XY problem.
From reading forum posts, I believe that confusing human-readable representations with numerical values is probably the single most common issue that gets newbies wrapped around the axle.
dougp:
If the starting string is '5A7', what do you expect to see as output?
I know what you mean, but how can I modify the program so that it knows between decimal number 78 and two separate numbers 7 and 8, this is the problem
gfvalvo:
I'd first ask why one wants / needs an ASCII string representing the value of a variable expressed in binary.
Could be an XY problem.
From reading forum posts, I believe that confusing human-readable representations with numerical values is probably the single most common issue that gets newbies wrapped around the axle.
i need the representation binaire for send the data by ook modulation
i need the representation binaire for send the data by ook modulation
Again I suggest following the path of Robin2's tutorial previously referenced.
First, you will enter a number in the serial monitor and send it to the Arduino.
The Arduino will read the characters of that number from the serial monitor. When it knows the entire number has been received it will convert the characters to an integer using atoi(). Like everything on the Arduino, that integer is stored within the Arduino's memory in binary.
You could then use bitRead() or bit shifting to access the binary values of that number and transmit them using the ook scheme.
light__fidelity:
i need the representation binaire for send the data by ook modulation
If that's your goal, then your approach is most definitely wrong. You don't need an ASCII representation of a binary number. All values in the processor are already in binary.
Say you want to send the value of a 32-bit variable (a uint32_t) over you (presumably) optical system. All you need to do is check the value of each of those 32 bits in a loop using C-language bitwise operators. If the bit is a '1', send a pulse. If not, don't.
Of course, you'll have to control the timing to achieve the desired bit rate.
isn't part of the problem recognizing the first bit and how to remain synchronized?
rs-232 data rate tolerances were 2% (tx could be +2 and receiver -2%). that's why ascii transmission is limited to 1 char such that timing remains ok until the stop bits and the known start bit signifies the start of a character
gfvalvo:
If that's your goal, then your approach is most definitely wrong. You don't need an ASCII representation of a binary number. All values in the processor are already in binary.
Say you want to send the value of a 32-bit variable (a uint32_t) over you (presumably) optical system. All you need to do is check the value of each of those 32 bits in a loop using C-language bitwise operators. If the bit is a '1', send a pulse. If not, don't.
Of course, you'll have to control the timing to achieve the desired bit rate.
Thanks for advice I'm realy want to send them by light
I am a newbee so please orient me more please what do I start since they are already represented inbinairy the microprocessor;
and yes yhe timing is important so I will review it later
I have to solve problems Step by Step
gcjr:
isn't part of the problem recognizing the first bit and how to remain synchronized?
rs-232 data rate tolerances were 2% (tx could be +2 and receiver -2%). that's why ascii transmission is limited to 1 char such that timing remains ok until the stop bits and the known start bit signifies the start of a character
That's certainly an issue at the receiver. But, OP hasn't even launched the pulses yet.
Different optical transmission systems handle it in different ways. SDH / SONET uses a fixed frame length with defined frame markers. To stay bit-synchronous, the receiver recovers clock from the data itself. That's why it includes PRBS scrambling to assure adequate transition density.
You could also do "optical RS232" as you imply. That's asynchronous but will work the same with optical pulses as bits on a wire. As you said, it has to tolerate clock rate slop between TX and RX.
gcjr:
isn't part of the problem recognizing the first bit and how to remain synchronized?
rs-232 data rate tolerances were 2% (tx could be +2 and receiver -2%). that's why ascii transmission is limited to 1 char such that timing remains ok until the stop bits and the known start bit signifies the start of a character
Yes, the synchronizationit is important and also bit start and bit stop, but frankly I tried a lot to understand the protocol rs-232 and add it, but I did not know enough and I could not succeed in it.
you might consider Manchester Encoding which effectively sends 2 transmission bits for each data bit where the first transmission bit may represent the data and the 2nd transmission bit is simply the opposite. so the transmitted data is constantly changing and encodes the clock. you still need a known start bit.
@light__fidelity, ask yourself how the program knows that the 7 you enter is going to be the 10's digit in a two digit decimal number or the thousands digit in a 4 digit decimal number, or the ones digit in a one digit decimal number?
Your entire approach with the Strings would be better replaced with the character array techniques presented in Robin2's tutorial on Serial Input Basics
yes i saw him but i can't combin thier exemple with my problm
cattledog:
stored within the Arduino's memory in binary.
You could then use bitRead() or bit shifting to access the binary values of that number and transmit them using the ook scheme.
Yes I did use bitRead () to access the binary values for this number and send it using the ook modulation. My problem is how do I make the computer understand and differentiate between 78 7,8