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 503285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:22:43+00:00 2026-05-13T06:22:43+00:00

I am writing code that compares 2 bytes which represent integers. I want to

  • 0

I am writing code that compares 2 bytes which represent integers. I want to see if byte R is with +-10 of G. The problem I am having with the code is with the comparison in the if-statment near the end. The bytes never come out as being out of range, even when they should. I am sure the problem comes from how I am adding/subtracting the error_range, but I don’t know any other way to do it.

I first considered converting the bytes into integers but I cannot find any help with that online. If that would work better than what I am doing here, please tell me how to do it.

Any help is appreciated!

const char ERROR_RANGE = 0x1010; //warning: overflow in implicit constant conversion
char R, G; /2 separate bytes
char buffer; //enough space for 1 byte

image = fopen(fileName,"r"); //open file

fread(&buffer, 1, 1, image); //read 1 byte  
memcpy (&R,&buffer,1); //store it as R

fread(&buffer, 1, 1, image); //read 1 byte   
memcpy (&G,&buffer,1); //store it as G

fclose(image);

if((R >= (G + ERROR_RANGE)) && (R <= (G - ERROR_RANGE)))
{
    printf("Outside of range!\n");
}

Thanks.

  • 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-13T06:22:43+00:00Added an answer on May 13, 2026 at 6:22 am

    Your problem is because your test says:

    if (R is greater than or equal to G + ERROR) AND (R is less than or equal to G – ERROR)

    it can’t be both.

    Replace the && with || in the first instance.

    A better test would be:

    if (the difference of R and G is greater than ERROR)

    which translates to:

    if (abs(R - G) > ERROR_RANGE)
    {
        printf("Error");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a code in which I want to search a datafile with
I am writing code that will spawn two thread and then wait for them
I am writing code that catches this OutOfMemoryException and throws a new, more intuitive
I'm using c#. In many cases I'm writing code that can benefit from a
I am a very proficient C# developer, but need to start writing code that
I'm writing some code that will take a screenshot of another application, given its'
I am writing some code that will go through a file, edit it as
I'm writing a code that uses bitboards. since iterating on all bits of a
I'm writing some code that has a lot of substitution. There's a list<char> productions
I am writing some code that connects to a website, and using C#, and

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.