473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

enum as flags - compare to byte

Hello everyone,

I have a field which is 1 byte long and is used to store different flags
(according to specs) - it is the flags bit in the ID3 tag header. So
0xabc00000 represents the byte, where only bits a,b and c have any meaning,
the other bits are always 0. I also have the following:
[Flags] enum ID3_Header_Flags {
NoFlag = 0x00000000,
FlagC = 0x00100000,
FlagB = 0x01000000,
FlagA = 0x10000000
};

When I compare the byte with the flag like
if (tagHeader[5] & ID3_Header_Flags.FlagX) where tagHeader is a byte[],
tagHeader[5] is the flags byte, and FlagX represents any of the Flags in the
enum, I get the following error:
"The operator '&' can not be used on Operands of type byte and
test02.Form1.ID3_Header_Flags".

And if I do [Flags] enum ID3_Header_Flags : byte, then the flags are too big
to fit in a byte....

Can you give me any hints what I'm doing wrong and how to solve my problem?
Any help is highly appreciated. Thanks in advance.

Nov 16 '05 #1
1 4130
Hi Todorov,

There are several errors in your code.
First, I assume you want binary flags, but 0x?? are hexadecimal numbers so any of your numbers are far too big to be compared to a byte. Try something like

[Flags] enum ID3_Header_Flags
{
NoFlag = 0x00000000,
FlagC = 0x00000001,
FlagB = 0x00000002,
FlagA = 0x00000004
};

Furthermore, comparing two numbers using & will not produce a boolean value. You will need to do something like

if (((ID3_Header_Flags)tagHeader[5] & ID3_Header_Flags.FlagX) > 0)

This casts the byte in tagHeader to a ID3_Header_Flags type and if number1 & number2 is larger than 0 we have a match. This of course will be 0 no matter what if you compare to NoFlag.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
6
by: Jim H | last post by:
I have an enum that is derived from byte and a member that is of type byte. The compiler complains when I try to OR the one of the enum values with the byte. Why? public enum eDataPosition :...
2
by: Keith Harris | last post by:
Hi, To exclude users based on a criteria, I have created an enum like so: public enum Exclusions:byte { None=0, HaveEmail=1, IsAdmin=2
1
by: Dwight.Dexter | last post by:
I have an enum variable. Is there some way to cast an int or BitArray and get my enum value? I have to communicate with an old C-style sever so I get an array of bits("0","1"). But I'm using an...
4
by: John Salerno | last post by:
I created this enumeration: enum Status { Off = 0, Red = 1, Yellow = 2, Blue = 4, Overload = 8
4
by: Christian.Wall | last post by:
Hello, I've got the following enum: public enum MyStates { None = 0 Saved = 1 New = 2
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
2
by: JB | last post by:
Hi All, I'm pulling my hair over this and could really do with a bit of help. I'm using various different enums as bit fields and I'd like to create a set of generic Functions or Subs to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.