I'm using an enum as a flag
[Flags] public enum SystemStatusEnum : long { Line_seizure = 1 << 0, Off_hook = 1 << 1, Initial_handshake_received = 1 << 2, Download_in_progress = 1 << 3, Dialer_delay_in_progress = 1 << 4, Using_backup_phone = 1 << 5, Listen_in_active = 1 << 6, Two_way_lockout = 1 << 7, Ground_fault = 1 << 8, Phone_fault = 1 << 9, Fail_to_communicate = 1 << 10, Fuse_fault = 1 << 11, Box_tamper = 1 << 12, Siren_tamper_trouble = 1 << 13, Low_Battery = 1 << 14, AC_fail = 1 << 15, Expander_box_tamper = 1 << 16, Expander_AC_failure = 1 << 17, Expander_low_battery = 1 << 18, Expander_loss_of_supervision = 1 << 19, Expander_auxiliary_output_over_current = 1 << 20, Auxiliary_communication_channel_failure = 1 << 21, Expander_bell_fault = 1 << 22, _6_digit_PIN_enabled = 1 << 24, Programming_token_in_use = 1 << 25, PIN_required_for_local_download = 1 << 26, Global_pulsing_buzzer = 1L << 27, Global_Siren_on = 1 << 28, Global_steady_siren = 1 << 29, Bus_device_has_line_seized = 1 << 30, Bus_device_has_requested_sniff_mode = 1 << 31, Dynamic_battery_test = 1 << 32, AC_power_on = 1L << 33, Low_battery_memory = 1L << 34, Ground_fault_memory = 1L << 35, Fire_alarm_verification_being_timed = 1L << 36, Smoke_power_reset = 1L << 37, _50_Hz_line_power_detected = 1L << 38, Timing_a_high_voltage_battery_charge = 1L << 39, Communication_since_last_autotest = 1L << 40, Power_up_delay_in_progress = 1L << 41, Walk_test_mode = 1L << 42, Loss_of_system_time = 1L << 43, Enroll_requested = 1L << 44, Test_fixture_mode = 1L << 45, Control_shutdown_mode = 1L << 46, Timing_a_cancel_window = 1L << 47, Call_back_in_progress = 1L << 55, Phone_line_faulted = 1L << 56, Voltage_present_interrupt_active = 1L << 57, House_phone_off_hook = 1L << 58, Phone_line_monitor_enabled = 1L << 59, Sniffing = 1L << 60, Last_read_was_off_hook = 1L << 61, Listen_in_requested = 1L << 62, Listen_in_trigger = 1L << 63, } Here I declare my flags =
SystemStatusEnum SystemStatusFlags = SystemStatusEnum.Off_hook | SystemStatusEnum.Phone_fault | SystemStatusEnum.Expander_bell_fault | SystemStatusEnum._6_digit_PIN_enabled | SystemStatusEnum.Timing_a_high_voltage_battery_charge | SystemStatusEnum.Loss_of_system_time | SystemStatusEnum.Call_back_in_progress | SystemStatusEnum.Phone_line_faulted; Here I convert the enum to 8 bytes
// System Status Flags Byte[] SystemStatusBytes = new Byte[8]; SystemStatusBytes[0] = (byte)((long)SystemStatusFlags & 0xff); SystemStatusBytes[1] = (byte)(((long)SystemStatusFlags >> 8) & 0xff); SystemStatusBytes[2] = (byte)(((long)SystemStatusFlags >> (8 * 2)) & 0xff); SystemStatusBytes[3] = (byte)(((long)SystemStatusFlags >> (8 * 3)) & 0xff); SystemStatusBytes[4] = (byte)(((long)SystemStatusFlags >> (8 * 4)) & 0xff); SystemStatusBytes[5] = (byte)(((long)SystemStatusFlags >> (8 * 5)) & 0xff); SystemStatusBytes[6] = (byte)(((long)SystemStatusFlags >> (8 * 6)) & 0xff); SystemStatusBytes[7] = (byte)(((long)SystemStatusFlags >> (8 * 7)) & 0xff); for (int i = 0; i < SystemStatusBytes.Count(); i++) { MessageBytes[Index++] = SystemStatusBytes[i]; } And here I convert them back to a list
private void ParseSystemStatusFlags(int Flag1, int Flag2, int Flag3, int Flag4, int Flag5, int Flag6, int Flag7, int Flag8) { long flagsRaw = (long)(Flag1 | Flag2 << 8 | Flag3 << (8 * 2) | Flag4 << (8 * 3) | Flag5 << (8 * 4) | Flag6 << (8 * 5) | Flag7 << (8 * 6) | Flag8 << (8 * 7)); SystemStatusEnum flags = (SystemStatusEnum)flagsRaw; SystemStatus_List = flags.GetFlags().ToList(); } But I'm getting an unexpected result, I get Off_hook,Two_way_lockout,Phone_fault,Fuse_fault,Expander_bell_fault,_6_digit_PIN_enabled as a result.
So some flags are correct, but Two_way_lockout for example is not declared in my enum.
What am I doing wrong?