Binary conserverion and inverting

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 ?

That is the ASCII code for the number 3.
In hex it's 0x33.
Just subtract 0x30.

Yes, that's puzzling
Maybe something wrong in the code you didn't post.

2 Likes

maybe inverting is wrong idea to convert an ASCII symbol "3" to integer value = 3.
either you replace Serial.print(3); by Serial.write(3); in sender
or subtract 48(0x30 or '0') from received byte - int IntegerNumber =Serial.read()-48;

yes ,it is ascii ,i think it make the ascii value but how it inverting ?please help ,me

noting in the code,code is simple .

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

}

void loop()
{
int intValue = 1234;

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

}

Where is the number 3 and where do you invert it.
Your code only prints 1234

this is 51 in decimal_ where you got this?

00110011
01100110
you shifting, not inverting

yes ,i want to invert this value

Do an XOR with 0xFF

A = B^0xFF; // A will be the invert of B

@edferc

a=~a

its outoput on MCU ,m not shifting this is the output of MCU and CRO

if i will do the xor of 3 then 3= 00110011 xor 11111111 = 11001100 it become 204 but answer that i am got from MCU is 102

Hello edferc

The result seems to be shifted right.

Post the current sketch to see what happens.

all data are not shfited in same way like for 1,2,3,4,5,6,7& 8 digit

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.