How do I convert a 12-bit cell phone number to a 6-byte array BCD code?

Source: Internet
Author: User


Converts a 12-bit cell phone number (11 digits before 0, such as 013482339442), converting 12 to 8421 yards, and then combining them into 6 byte arrays, tentatively named BCD6, the conversion method is as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Consoledemo
{public
    class BCD6
    {public
        string Getmobileno (byte[] mobilearray)
        {
            StringBuilder sb = new StringBuilder ();
            for (int i = 0; i < 6; i++)
            { 
                byte bb=mobilearray[i];
                Sb. Append (((Byte) (BB >> 4)). ToString ());
                Sb. Append ((Byte) ((Byte) (BB << 4) >> 4). ToString ());
            }
            Return SB. ToString ();
        }

        Public byte[] ConvertToBCD6 (string mobileno)
        { 
            byte[] mobilearray=new byte[6];
            if (mobileno.length!=) return mobilearray;
            for (int i = 0; i < 6; i++)
            {
                Mobilearray[i] = Convert.tobyte (Mobileno.substring (i*2, 2);
            }
            return mobilearray;
        }
    }


Console test Code:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Consoledemo
{
    class program
    {
        static void Main (string[] args)
        {

            byte[] Mobilearray = new Byte[6] {0x01, 0x34, 0x82, 0x33, 0x94, 0x42};
            BCD6 bcd6 = new BCD6 ();
            Console.WriteLine (Bcd6. Getmobileno (Mobilearray));

            byte[] Mobile2 = bcd6. ConvertToBCD6 ("013482339442");
            Console.WriteLine (Bcd6. Getmobileno (Mobile2));

            Console.read ();}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.