Skip to main content
Ranjeet Singh
Senior
June 21, 2023
Question

binary and invert converion

  • June 21, 2023
  • 7 replies
  • 7105 views

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 ?

This topic has been closed for replies.

7 replies

Karl Yamashita
Principal
June 21, 2023

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

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Ranjeet Singh
Senior
June 22, 2023

noting in the code just sent data on serial 

Graduate II
June 21, 2023

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

 

Ranjeet Singh
Senior
June 22, 2023

you are  right ,but how it inverting ?

Tesla DeLorean
Guru
June 22, 2023

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 VenmoUp vote any posts that you find helpful, it shows what's working..
Ranjeet Singh
Senior
July 12, 2023

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

Tesla DeLorean
Guru
July 12, 2023

Ok, but what part / product are we even talking about here? Present the problem better, you'll get better answers..

RS232 level shifters implicitly "invert" the level. Out of CMOS drivers on an MCU the line is typically HIGH in the idle state, the START bit is LOW, and the data bits shift out LSB first, and normal/expected logic levels, ie 0 LOW, 1 HIGH

Some of the newer STM32 families have UART pins can be logically inverted as part of the Advanced Features.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
RhSilicon
Lead
July 15, 2023

@Ranjeet Singh wrote:

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 ?


How is it possible to convert "3" in decimal to "00110011" in binary?

If it is "3" from the ASCII table then it is necessary to convert ASCII to decimal:

The value of the character "3" from the ASCII table is not 3 in decimal. The value of the character "3" in ASCII is 51 in decimal:

ASCII_table_3.png

Table here: https://www.ascii-code.com/

Since characters start from "0" to "9", a programmer can convert the character "3" to ASCII by removing the value of the character "0" in ASCII.

This way the decimal value of the ASCII character "3" = equal to the value of "3" - "0" = (51) - (48) = 3 (which is 3 in decimal).

No inversion occurs anywhere in this conversion.

RhSilicon
Lead
July 15, 2023

Note that the character "3" from the ASCII table is considered just a SYMBOL, not the relative position value (which would be 51 in decimal base, or 063 in octal base, or 33 in hexadecimal base).

"ASCII: Converting Symbols to Binary

The American Standard Code for Information Interchange (ASCII) was an early standardized encoding system for text. Encoding is the process of converting characters in human languages into binary sequences that computers can process.

ASCII’s library includes every upper-case and lower-case letter in the Latin alphabet (A, B, C…), every digit from 0 to 9, and some common symbols (like /, !, and ?). It assigns each of these characters a unique three-digit code and a unique byte."

"The number of characters that ASCII can represent is limited to the number of unique bytes available, since each character gets one byte. If you do the math, you’ll find that there are 256 different ways of groups eight 1s and 0s together. This gives us 256 different bytes, or 256 ways to represent a character in ASCII. When ASCII was introduced in 1960, this was okay, since developers needed only 128 bytes to represent all the English characters and symbols they needed."

https://blog.hubspot.com/website/what-is-utf-8

Graduate II
July 22, 2023

Hello

If external logic inverter helps to get right data, probably setting Rx line inversion on does the same thing (or Tx line). It seems that data is totally interved when it goes thru IR transmitter and receiver.

If you are using STM32/HAL/Cube you should find this setting under advanced features of Uart/Usart:

JTP1_1-1690021354934.png

Maybe this way you finally get your data inverted :D

Br J.T

 

Ranjeet Singh
Senior
July 24, 2023

right

RhSilicon
Lead
August 5, 2023

If the problem is still open, it might be a good idea to unmark the post already accepted as a solution (perhaps accidentally, due to a problem with the "Accept solution" button's update time) so that other users can try to help.

Not_Solution.png

Ranjeet Singh
Senior
August 11, 2023

kindly help