Skip to main content
Vmere.1
Associate III
August 3, 2022
Solved

Bitwise

"I'll delete this question once someone answers it, as it is not relevant".

0693W00000QMqCCQA1.pngWhy in second line did some one write ch & 0xFF? ch limits are already 0 to 255 right?

    This topic has been closed for replies.
    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    August 3, 2022

    The copy-n-paste coder here took code that use int originally for the parameter/return and changed it to a uint8_t

    Classically C libraries have returned negative values for failure around STDIO routines.

    The TDR here is 16-bit wide as the U(S)ART support 9-bit values. When reading RDR and using parity, the code needs to strip the parity bit manually/

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

    4 replies

    S.Ma
    Principal
    August 3, 2022

    Maybe because function content was copy pasted from elsewhere which ch may not have been uint8_t. Anyway, compiler are not dumb, they will optimise this, no sweat.

    KnarfB
    Super User
    August 3, 2022

    You're right. The &0xFF is useless here.

    hth

    KnarfB

    Vmere.1
    Vmere.1Author
    Associate III
    August 4, 2022

    I'm new to C programming, development and not very confident but after few months (till today) I got used to programming and sometime still don't feel 100% confident, don't know why! But i feel that this emotion will be gone gradually.​

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    August 3, 2022

    The copy-n-paste coder here took code that use int originally for the parameter/return and changed it to a uint8_t

    Classically C libraries have returned negative values for failure around STDIO routines.

    The TDR here is 16-bit wide as the U(S)ART support 9-bit values. When reading RDR and using parity, the code needs to strip the parity bit manually/

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