-2

I'm confused in bitmasks, bitflags, and other "bit" stuff. I have a list of error codes - like [102, 104, 108, 80000000, 8000000, 10000000, 1000000, 0x0008000, ....]. Part of it writing in system logs like bitflags, f.e. "67108864" (and part of them not, and return normal numbers). I need to match them, but I can not find any algorithm. How I can do that? Maybe it used only for codes like "0x0008000"? If it is true how to define which of this?

The problem is deeper. I do not understand byte flags. I understand that flags usually used for boolean states, but here is logged status codes. For example, 102 is (1100110)2. Byte flag for that number is 2+4+32+64 ... It is how I do transform int to binary form, and it is obviously equal 102. So I'm confused.

Thanks for your time!

Pruntoff
  • 615
  • 3
  • 8
  • 18
  • Your question is not clear, partly because you ask multiple questions and partly because you do not specify a programming language. This is not a tutorial site, so please limit your question and make it more clear. – Rory Daulton Mar 20 '19 at 08:49
  • Ok, sorry about that. This unclearness comes from my misunderstanding of the task and topic. I can not edit answers, so the main question is how to compare the list of codes `list1 = [102, 8000000, 0x0008000, ....]` with the list of mixed codes and flags, which represent a part of codes - `list2 = [102, 67108864, ...]` (`set(list1) != set(list2)`) and find out which code is represented by bitflag using python. – Pruntoff Mar 20 '19 at 10:47

1 Answers1

0

You have to separate

  • numbered error/message codes (usually values in some range like 101, 102, 103... or in some ranges) - they just specify what error is occured, this error (like "file isn't found") is fully qualified (at least message creators believe :))

  • codes containing set of flags (usually written in hex or binary notation if available) - they give us details, every bit contains a piece of information.

MBo
  • 77,366
  • 5
  • 53
  • 86