Re: Integer conversion to Binary Coded Decimal

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



At the moment I seem to be doing the following:

int ------> string
string ----> char []
foreach (char c in char [])
{
c -------> byte
byte ----> binary string
binary string -----> string []
}

then combine the items in the string [] into 8 character strings and convert
to hex. I am getting the conversion but it seems like a lot of work for
something I thought the framework would provide.

Any thoughts?




"Stefan L" wrote:

Hmmm...
What exactly do you mean with a smart way? Whether there's a function in
the framework doing it for you? I guess ... no. But I'm not sure here.

On the other hand: Why worrying about a function that requires 10 lines
of code?

regards,
Stefan



Kenney schrieb:
Hi All,

I work with communications protocols (namely TCPIP) and I have been asked to
transmit the length of a message in Binary Coded Decimal. For example a
message of length (int) 356 will be transmitted as 0x03, 0x56.

Is there a smart way to to this?

Cheers,
Kenney

.



Relevant Pages

  • Permuting beyond one collection
    ... where the columns represent a char[]. ... string number = Console.In.ReadLine; ... foreach ... ArrayListnewOptions = new ...
    (comp.programming)
  • Re: checking to see if a string contains every letter of the alpha
    ... Using a bitmap might be more efficient than allocating a hash table ... ... foreach (char ch in str) ... > foreach(char c in string.ToCharArray()) ... >> see if a string contains every letter of the alphabet. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Fast way to read string one char at a time
    ... string one char at a time. ... fairly good idea as to why the "for" loop is fast. ... the "foreach" loop is pretty much unusable because I'm not really going to ... string given an char index. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: foreach with a string and Hashtable
    ... The foreach uses the IEnumerable interface to enumerate through the ... enumerates the characters in the string. ... from the linetext variable rather than each character. ...
    (microsoft.public.dotnet.languages.csharp)
  • [PATCH 09/21] perf: rewire generic library stuff, p5
    ... +int eprintf(int level, const char *fmt, ...) ... * Helper function for splitting a string into an argv-like array. ... +static int count_argc(const char *str) ...
    (Linux-Kernel)