base 64 encoder code example

Example 1: base64decode C#

string base64Encoded = "your-encoded-text";
string base64Decoded;
byte[] data = System.Convert.FromBase64String(base64Encoded);
base64Decoded = System.Text.ASCIIEncoding.ASCII.GetString(data);

Example 2: JavaScriptSerializer() and convert to base64

class Program
{
    static void Main(string[] args)
    {
        var account = new ExternalAccount() { Name = "Someone" };
        string json = JsonConvert.SerializeObject(account);
        string base64EncodedExternalAccount = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));
        byte[] byteArray = Convert.FromBase64String(base64EncodedExternalAccount);

        string jsonBack = Encoding.UTF8.GetString(byteArray);
        var accountBack = JsonConvert.DeserializeObject<ExternalAccount>(jsonBack);
        Console.WriteLine(accountBack.Name);
        Console.ReadLine();
    }
}

[Serializable]
public class ExternalAccount
{
    public string Name { get; set; }
}

Example 3: Int64

sbyte value1 = 124;
short value2 = 1618;
int value3 = Int32.MaxValue;

long number1 = value1;
long number2 = value2;
long number3 = value3;

Example 4: Int64

ulong ulNumber = 163245617943825;
try {
   long number1 = (long) ulNumber;
   Console.WriteLine(number1);
}
catch (OverflowException) {
   Console.WriteLine("{0} is out of range of an Int64.", ulNumber);
}

double dbl2 = 35901.997;
try {
   long number2 = (long) dbl2;
   Console.WriteLine(number2);
}   
catch (OverflowException) {
   Console.WriteLine("{0} is out of range of an Int64.", dbl2);
}
   
BigInteger bigNumber = (BigInteger) 1.63201978555e30;
try {
   long number3 = (long) bigNumber;
   Console.WriteLine(number3);
}
catch (OverflowException) {
   Console.WriteLine("{0} is out of range of an Int64.", bigNumber);
}    
// The example displays the following output:
//    163245617943825
//    35902
//    1,632,019,785,549,999,969,612,091,883,520 is out of range of an Int64.

Example 5: base64

function getBase64(file:any) {
    return new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => resolve(reader.result);
      reader.onerror = error => reject(error);
    });
  }