cancel
Showing results for 
Search instead for 
Did you mean: 

binary and invert converion

Ranjeet Singh
Senior

i am sending data on serial is 3 when is display is this 3 but i can conver in bninary then become 00110011 instead 00000011.and when i invert it then i got 01100110 instead of 11111100 ,why so ?

33 REPLIES 33
Karl Yamashita
Lead III

We have no idea what you're doing unless you show some code. And what is "display"?

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.
JTP1
Lead

Hello. I guess you are mixing Ascii and binary coding. Ascii symbol '3' equals 51 decimal value and it is 00110011 in binary

 

noting in the code just sent data on serial 


void setup()
{
    Serial.begin(2400);

   
}

void loop()
{
   int intValue = 1234;


     Serial.println(intValue);
     delay(1000);
}

you are  right ,but how it inverting ?

It's hard to understand what you're explaining here. Show code that's sending the data, and how you determine it's inverted, like a scope or logic analyzer plot.

'3' (the character) and 3 the number are represented differently inside the computer.

Serial UART data is typically shifted least-significant bit FIRST.

Data shifted out at CMOS levels, the line is normally HIGH between bytes, and there is a LOW start bit, and a high STOP bit.

0110000001 with start and stop bits (10 clocked bits in 8N1 format)

RS232 level converters effectively invert the signal. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

how to invert it 


@Ranjeet Singh wrote:

how to invert it 


Perhaps you are looking for this? (bitwise)

var2 = ~(val1);

STM32duino GPIO Registers and Programming

https://gist.github.com/Vitorbnc/e35f1ff1485d660edf365241dacfa387

 

Ranjeet Singh
Senior

this is just make 0 to 1 and 1 to 0 but not inverting as the Microcontroller/CRO invert