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

  • Home
  • SEARCH
  • 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 40737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:04:14+00:00 2026-05-10T15:04:14+00:00

I have the following C# code: byte rule = 0; … rule = rule

  • 0

I have the following C# code:

byte rule = 0; ... rule = rule | 0x80; 

which produces the error:

Cannot implicitly convert type ‘int’ to ‘byte’. An explicit conversion exists (are you missing a cast?)

[Update: first version of the question was wrong … I misread the compiler output]

Adding the cast doesn’t fix the problem:

rule = rule | (byte) 0x80; 

I need to write it as:

rule |= 0x80; 

Which just seems weird. Why is the |= operator any different to the | operator?

Is there any other way of telling the compiler to treat the constant as a byte?


@ Giovanni Galbo : yes and no. The code is dealing with the programming of the flash memory in an external device, and logically represents a single byte of memory. I could cast it later, but this seemed more obvious. I guess my C heritage is showing through too much!

@ Jonathon Holland : the ‘as’ syntax looks neater but unfortunately doesn’t appear to work … it produces:

The as operator must be used with a reference type or nullable type (‘byte’ is a non-nullable value type)

  • 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. 2026-05-10T15:04:14+00:00Added an answer on May 10, 2026 at 3:04 pm
    int rule = 0; rule |= 0x80; 

    http://msdn.microsoft.com/en-us/library/kxszd0kx.aspx The | operator is defined for all value types. I think this will produced the intended result. The ‘|=’ operator is an or then assign operator, which is simply shorthand for rule = rule | 0x80.

    One of the niftier things about C# is that it lets you do crazy things like abuse value types simply based on their size. An ‘int’ is exactly the same as a byte, except the compiler will throw warnings if you try and use them as both at the same time. Simply sticking with one (in this case, int) works well. If you’re concerned about 64bit readiness, you can specify int32, but all ints are int32s, even running in x64 mode.

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

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You could do many-to-many relationships between POST and CATEGORY and… May 11, 2026 at 9:48 am
  • added an answer Try this out: grep -i 'killed process' /var/log/messages May 11, 2026 at 9:48 am
  • added an answer The Wikipedia page you linked to has steps on how… May 11, 2026 at 9:48 am

Related Questions

I have the following C# code: byte rule = 0; ... rule = rule
I have the following fields: Inventory control (16 byte record) Product ID code (int
Suppose I have the following C code. unsigned int u = 1234; int i
I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
Say I have the following code snippet in c# static const bool DO_PERFORMANCE_CODE =
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
I have a C# application that includes the following code: string file = relativePath.txt;
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.