Decoding a Base64-encoded Binary : String : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » String »

 

Decoding a Base64-encoded Binary









    


using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Text;
class Class1{
        static void Main(string[] args){
             Console.WriteLine(Base64EncodeBytes(new byte[5] {45,34,23,54,38}));
         }
    public static string Base64EncodeBytes(byte[] inputBytes) 
    {
      // Each 3 byte sequence in inputBytes must be converted to a 4 byte sequence 
      long arrLength = (long)(4.0d * inputBytes.Length / 3.0d);
      if ((arrLength  % 4) != 0) 
      {
        // increment the array lenght to the next multiple of 4 if it is not already divisible by 4
        arrLength += 4 - (arrLength % 4);
      }
    
      char[] encodedCharArray = new char[arrLength];
      Convert.ToBase64CharArray(inputBytes, 0, inputBytes.Length, encodedCharArray, 0);
      
      return (new string(encodedCharArray));
    }      
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» String