public static void Main()
ulong ecgi = 51681341509633;
Console.WriteLine("ECGI is " + ecgi);
Console.WriteLine("ECGI is " + GetEcgi(GetPlmnId(ecgi), GetCellIdentity(ecgi)));
Console.WriteLine("ECGI is " + GetEcgi(GetPlmn(GetMcc(GetPlmnId(ecgi)),GetMnc(GetPlmnId(ecgi))), GetCellIdentity(ecgi)));
Console.WriteLine("ECGI is " + GetEcgi(GetPlmn("200","01"), 36865));
Console.WriteLine("PLMN is " + GetPlmnId(ecgi));
Console.WriteLine("PLMN is " + GetPlmn(GetMcc(GetPlmnId(ecgi)),GetMnc(GetPlmnId(ecgi))));
Console.WriteLine("Cell Identity is " + GetCellIdentity(ecgi));
Console.WriteLine("MCC is " + GetMcc(GetPlmnId(ecgi)));
Console.WriteLine("MCC is " + GetMcc(GetPlmn(GetMcc(GetPlmnId(ecgi)),GetMnc(GetPlmnId(ecgi)))));
Console.WriteLine("MNC is " + GetMnc(GetPlmnId(ecgi)));
Console.WriteLine("MNC is " + GetMnc(GetPlmn(GetMcc(GetPlmnId(ecgi)),GetMnc(GetPlmnId(ecgi)))));
static string GetMcc(uint plmn)
byte[] byteArray = BitConverter.GetBytes(plmn);
return (byteArray[3] & 0x0F).ToString() + ((byteArray[3] & 0xF0) >> 4).ToString() + (byteArray[2] & 0x0F).ToString();
static string GetMnc(uint plmn)
byte[] byteArray = BitConverter.GetBytes(plmn);
if ((byte)((byteArray[2] & 0xF0) >> 4) == 0x0F)
return (byteArray[1] & 0x0F).ToString() + ((byteArray[1] & 0xF0) >> 4).ToString();
return ((byteArray[2] & 0xF0) >> 4).ToString() + (byteArray[1] & 0x0F).ToString() + ((byteArray[1] & 0xF0) >> 4).ToString();
static uint GetPlmn(string Mcc, string Mnc)
if (Mcc.Length != 3 || Mnc.Length < 2 || Mnc.Length > 3)
var MccVal = Mcc.ToCharArray();
var MncVal = Mnc.ToCharArray();
byte[] plmn = new byte[6];
byte[] plmnarray = new byte[4];
plmn[0] = Convert.ToByte(MccVal[1]);
plmn[1] = Convert.ToByte(MccVal[0]);
plmn[2] = (MncVal.Length == 2) ? (byte)0x0F : Convert.ToByte(MncVal[0]);
plmn[3] = Convert.ToByte(MccVal[2]);
plmn[4] = (MncVal.Length == 2) ? Convert.ToByte(MncVal[1]) : Convert.ToByte(MncVal[2]);
plmn[5] = (MncVal.Length == 2) ? Convert.ToByte(MncVal[0]) : Convert.ToByte(MncVal[1]);
plmnarray[0] = (byte)((byte)(plmn[0] << 4) ^ (byte)(plmn[1] & 0x0F));
plmnarray[1] = (byte)((byte)(plmn[2] << 4) ^ (byte)(plmn[3] & 0x0F));
plmnarray[2] = (byte)((byte)(plmn[4] << 4) ^ (byte)(plmn[5] & 0x0F));
Array.Reverse(plmnarray);
return BitConverter.ToUInt32(plmnarray, 0);
public static ulong GetEcgi(uint plmn, uint cellIdentity)
return plmn * 1048576UL + cellIdentity;
public static uint GetCellIdentity(ulong ecgi)
return (uint)(ecgi % 268435456);
public static uint GetPlmnId(ulong ecgi)
return (uint)(256 * (ecgi / 268435456));