shhhhh… they are busy reinventing the wheel discovering the obvious,
leave them alone.
-----Original Message-----
From: Mathieu Routhier [mailto:xxxxx@guillemot.com]
Sent: Wednesday, April 16, 2003 2:29 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driverWhat’s the point in writing that kind of code when you could
simply #include <stdio.h> and call sprintf()?
>
> OF COURSE, that will run faster if you define a function
> which will do just the minimum you need. But is it really
> worth the time and risk of bug?
>
> Unless that function is in a tight loop, I would rather use
> sprintf()… Any objections?
>
> Mat
>
> -----Original Message-----
> From: Christiaan Ghijselinck
> [mailto:xxxxx@CompaqNet.be]
> Sent: Wednesday, April 16, 2003 2:12 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
>
>
> Ho, here we go …
>
> I hope that the ( two ) question poster guy(s) didn’t commit
> suicide after all previous comments … :)))
>
> Christiaan
>
> /------------------------------------------------------------
> --------------
> -------------------/
>
>
> UCHAR aValToCharConverter[16] = {
> ‘0’,‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’,‘8’,‘9’,‘A’,‘B’,‘C’,‘D’,‘E’,‘F’ } ;
>
> VOID ConvertSequence ( IN ULONG nBinarySequenceSize ,
> IN PVOID
> pBinarySequence ,
>
>
> # pragma pack ( 1 )
> typedef UCHAR UCHARARRAY ;
> typedef UCHARARRAY pUCHARARRAY ;
> # pragma pack ( )
>
> CCHAR _cSequenceBuffer[128]; // OUTPUT
>
> UCHAR _bytevalue ;
> UCHAR _lnibble ;
> UCHAR _hnibble ;
>
> ULONG _binindex ;
>
>
> / convert the binary strings into character strings /
>
> for ( _binindex = 0 ; _binindex < nBinarySequenceSize ;
> _binindex++ )
> {
> / next code seems to generate the smallest amount of
> ASM instructions /
> _bytevalue = ((pUCHARARRAY)pBinarySequence)[_binindex] ;
>
> _lnibble = aValToCharConverter[_bytevalue & 0x0F] ;
> _hnibble = aValToCharConverter[_bytevalue >> 4] ;
>
> _cSequenceBuffer[(_binindex << 1)] = _hnibble ;
> _cSequenceBuffer[(_binindex << 1) + 1] = _lnibble ;
> }
>
> _cSequenceBuffer[nBinarySequenceSize << 1] = 0 ; /* string
> closing zero */
>
>
> …
>
>
> }
>
>
>
>
>
>
>
> ----- Original Message -----
> From: “Moreira, Alberto”
> To: “NT Developers Interest List”
> Sent: Wednesday, April 16, 2003 6:40 PM
> Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
>
>
> > Here, a very simple function - three lines of code - and a naive C++
> tester
> > to go with it. The “issue” call puts the characters out,
> one by one.
> > You guys can convert it to assembler if you will, but I don’t think
> > it’s necessary.
> >
> > Hope this helps !
> >
> > Alberto.
> >
> > //==============================================================
> > void convert(int n)
> > {
> > char *k = “0123456789ABCDEF”;
> > if (n > 15) convert(n>>4);
> > issue (k[n&0xf]);
> > } //==============================================================
> >
> > //==============================================================
> > #include
> > using namespace std;
> >
> > #define BUFFERSIZE 16
> >
> > static char c[BUFFERSIZE];
> > static int p=0;
> >
> > void convert(int n)
> > {
> > char *k = “0123456789ABCDEF”;
> > if (n > 15) convert(n>>4);
> > issue (k[n&0xf]);
> > }
> >
> > void prime()
> > {
> > p = 0;
> > for (int i=0; i> > }
> >
> > void issue(int digit)
> > {
> > c[p++] = digit;
> > c[p] = 0;
> > }
> >
> >
> > main()
> > {
> > prime(); convert(0); cout << c << endl;
> > prime(); convert(0x1); cout << c << endl;
> > prime(); convert(0x12); cout << c << endl;
> > prime(); convert(0x123); cout << c << endl;
> >
> > return 0;
> > } //==============================================================
> >
> > ----Original Message-----
> > From: Daniel E. Germann [mailto:xxxxx@nospam.visi.com]
> > Sent: Wednesday, April 16, 2003 9:10 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> >
> >
> > Ahem. Allow me to kick myself in the pants. Please accept this
> correction:
> > add al,90h
> > daa
> > adc al,40h
> > daa
> >
> > -Dan
> >
> > ----- Original Message -----
> > From: “Daniel E. Germann”
> > To: “NT Developers Interest List”
> > Sent: Wednesday, April 16, 2003 8:06 AM
> > Subject: Re: Binary/Hex to ASCII conversion in driver
> >
> >
> > > OK, don’t flame me. My favorite binary-to-ASCII
> conversion on the
> > > x86 platform is to put the 4-bit binary value I want to
> convert to
> > > ASCII in
> > the
> > > AX register and then do:
> > >
> > > add al,40h
> > > daa
> > > adc al,90h
> > > daa
> > >
> > > The result is an ASCII hex digit in the AX register. It’s not
> > > portable,
> > but
> > > it is a nifty piece of code.
> > >
> > > I think credit for this goes to Tim Paterson at Seattle Computer
> Products
> > > (circa 1980). At least that’s the first reference I saw to this
> > particular
> > > method.
> > >
> > > -Dan
> > >
> > > ----- Original Message -----
> > > > Subject: Binary/Hex to ASCII conversion in driver
> > > > From: Tom Pr
> > > > Date: Tue, 15 Apr 2003 16:36:02 -0700 (PDT)
> > > >
> > > > Hi All,
> > > >
> > > > How should I convert my 8 bit binary/Hex value to corresponding
> > > > ASCII in my device driver.
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as:
> > xxxxx@compuware.com To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
> >
> >
> > The contents of this e-mail are intended for the named
> addressee only.
> > It contains information that may be confidential. Unless
> you are the
> > named addressee or an authorized designee, you may not copy
> or use it,
> > or
> disclose
> > it to anyone else. If you received it in error please notify us
> immediately
> > and then destroy it.
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as:
> xxxxx@compaqnet.be
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@guillemot.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
></stdio.h>