Issue
I'm trying to convert a 5 digit decimal value (ranging from 00001 to 99999) and somehow represent it as a 24-bit value split into 3 bytes but have tried every conversion and bitshift tactic I know, but keep getting stuck :/
Example: decimal value is 12345, and I need to send 3 hex values [aa][bb][cc], which would consist of:
[aa] - least significant | [bb] - middle | [cc] - most significant
I'm hoping I'm not in over my head and that there is a simple answer, thanks in advance!
Solution
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Decimal number = new Decimal() { number = 12345 };
            string output = number.ToString();
        }
    }
    public class Decimal
    {
        public int number { get; set; }
        public override string ToString()
        {
            string output = string.Format("[{0}][{1}][{2}]",
                (number & 0xFF).ToString("X2"),
                ((number >> 8) & 0xFF).ToString("X2"),
                ((number >> 16) & 0xFF).ToString("X2"));
            return output;
        }
    }
}
Answered By - jdweng Answer Checked By - Timothy Miller (PHPFixing Admin)
 
 Posts
Posts
 
 
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.