Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7056763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:54:20+00:00 2026-05-28T03:54:20+00:00

Working with a Microchip 18f4620 PIC. This should be a standard ANSI C question,

  • 0

Working with a Microchip 18f4620 PIC. This should be a standard ANSI C question, though.

Say I have

unsigned int16 badFlow=65535 //max unsigned int16 value

This has a binary value of 1111 1111 1111 1111.

if I then

badFlow++;

the bit pattern becomes 1 0000 0000 0000 0000
17 bits. Obviously badFlow == 0, but the additional flipped bit either

  1. gets discarded
  2. or resides at wherever byte* flowPtr = &badFlow+2;
    points.

I’m assuming the latter, but hoping for the former.

My problem: a coworker has written some bad code with a counter that has been overflowing on all produced products for ~2 years. Considering what our customers charge for use of these tools, that’s a few million dollars in peril due to potentially bad data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:54:21+00:00Added an answer on May 28, 2026 at 3:54 am

    Arithmetic in C takes place with values, not bytes in memory. Your expression badFlow++ is equivalent to badFlow = badFlow + 1. The right-hand side is evaluated as type int (due to default promotions, assuming int is larger than 16 bits; if int is only 16 bits then it would be evaluated as unsigned int) resulting in 65536, then when 65536 is assigned into an unsigned 16-bit variable, it is reduced modulo 65536, resulting in 0.

    The important thing to get out of this answer is that badFlow++ is not a direct operation on the memory at &badFlow (although it could possibly be implemented as such on some implementations). It’s simply shorthand for an addition and assignment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preface: This question is about a project I am working on with a professor
I have a question regarding stepper motor control while using the Microchip TCP/IP stack.
Working with a Lucene index, I have a standard document format that looks something
Working on a project at the moment and we have to implement soft deletion
I am working with a Microchip dsPIC33FJ128GP802. It's a small DSP-based microcontroller, and it
Working on this page: http://www.karlsenner.dreamhosters.com/about.php and having trouble with the navigation in IE6. It
I'm working with Microchip's free TCP/IP (version 4.55) stack on an 8-bit micro-controller. I'm
I'm currently using Microchip's Fixed Point Library, but I think this applies to most
Working with some basic java apps on CentOS 5 linux and I have my
Working on this EF tutorial , I've difficult to understand the meaning of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.