using System;

namespace QCRPG.TSL.NFC.NVM;

public class NVMDataConversions
{
	public static uint GetFieldMask(Field field)
	{
		uint num = 0u;
		if (field.LengthBits == 32)
		{
			return uint.MaxValue;
		}
		return (uint)((1 << field.LengthBits) - 1 << field.LSBLocation);
	}

	public static uint GetFieldValue(string parameterDefaultValueString, Field field)
	{
		uint num = Convert.ToUInt32(parameterDefaultValueString, 16);
		uint fieldMask = GetFieldMask(field);
		return (num & fieldMask) >> field.LSBLocation;
	}

	public static uint GetNewParameterValueFromNewFieldValue(Parameter parameter, Field field, uint newValue)
	{
		uint fieldMask = GetFieldMask(field);
		uint num = ~fieldMask;
		uint num2 = Convert.ToUInt32(parameter.ValueHex, 16) & num;
		return num2 | ((newValue << field.LSBLocation) & fieldMask);
	}

	public static string StripNewLinesInText(string text)
	{
		text = text.Replace("\n", "\r");
		text = text.Replace("\r\r", "\r");
		text = text.Replace("\r", " / ");
		return text;
	}
}
