Binary/Hex to ASCII conversion in driver

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 driver

What’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>

Well…

(1) It’s my code, and I trust my hand better than anyone else’s, (2) I don’t
use anything in my service routines that’s not strictly ANSI C, so, I don’t
depend on someone else’s headers, (3) I can tailor it exactly to what I
need, (4) I can give my file a .cpp extension and take advantage of C++
features not available in C, and (5) I can write it an test it in way less
time it would take me to learn how sprintf works or what’s the semantics of
the Microsoft types.

It may be my own professional bias, but I like to minimize the number of
strings attached to my code !

Alberto.

-----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 driver

What’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@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.</stdio.h>

Mm let me think…

(1) It’s my code, and I trust my hand better than anyone else’s

Coming from the mouth of someone who pushes a certain driver framework
library, that statement seems contradictory.

(2) I don’t
use anything in my service routines that’s not strictly ANSI C, so, I don’t
depend on someone else’s headers,

sprintf() is ANSI C. Isn’t it?
http://www.lysator.liu.se/c/rat/d9.html#4-9-6-5

(5) I can write it an test it in way less
time it would take me to learn how sprintf works or what’s the semantics of
the Microsoft types.

I thought everyone who learned C/C++ was familiar with the printf()
function. Maybe I shouldn’t make that assumption? In any case, learning
sprintf() is definitely worth the effort: it will save you time every single
occasion where you need to format data into a string! You won’t even need
to write a special function. sprintf() must be the standard function I use
the most.

Mat

-----Original Message-----
From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Wednesday, April 16, 2003 3:55 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

Well…

(1) It’s my code, and I trust my hand better than anyone else’s, (2) I don’t
use anything in my service routines that’s not strictly ANSI C, so, I don’t
depend on someone else’s headers, (3) I can tailor it exactly to what I
need, (4) I can give my file a .cpp extension and take advantage of C++
features not available in C, and (5) I can write it an test it in way less
time it would take me to learn how sprintf works or what’s the semantics of
the Microsoft types.

It may be my own professional bias, but I like to minimize the number of
strings attached to my code !

Alberto.

-----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 driver

What’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@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@guillemot.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</stdio.h>

> -----Original Message-----

From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Wednesday, April 16, 2003 12:55 PM


> (2) I don’t
> use anything in my service routines that’s not strictly ANSI
> C, so, I don’t
> depend on someone else’s headers

I’m Shocked! Shocked!

Dude. sprintf() IS ANSI C. Note the following from the standard MSVC/C++
6.0 help:


sprintf, swprintf
Write formatted data to a string.

int sprintf( char *buffer, const char *format [, argument] … );
int swprintf( wchar_t *buffer, const wchar_t format [, argument] … );

Routine Required Header Compatibility
sprintf <stdio.h> ANSI, Win 95, Win NT
swprintf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT


Example

/
SPRINTF.C: This program uses sprintf to format various
* data and place them in the string named buffer.
/

#include <stdio.h>

void main( void )
{
char buffer[200], s[] = “computer”, c = ‘l’;
int i = 35, j;
float fp = 1.7320534f;

/
Format and print various data: */
j = sprintf( buffer, “\tString: %s\n”, s );
j += sprintf( buffer + j, “\tCharacter: %c\n”, c );
j += sprintf( buffer + j, “\tInteger: %d\n”, i );
j += sprintf( buffer + j, “\tReal: %f\n”, fp );

printf( “Output:\n%s\ncharacter count = %d\n”, buffer, j );
}

Output

Output:
String: computer
Character: l
Integer: 35
Real: 1.732053

character count = 71</stdio.h></wchar.h></stdio.h></stdio.h>

For anyone considering string manipulation of this sort may I strongly
encourage you to check out strsafe.h that lives in the DDK under
inc\crt.

You’ll find alternatives to the standard CRT string manipulation
functions that help avoid some of the common pitfalls we see with string
manipulation (buffer overruns etc.), all of which were developed as part
of the Windows security initiative last year.

Please let us know if you have feedback - positive or negative!

= Mike =

This posting is provided “AS IS” with no warranties, and confers no
rights

-----Original Message-----
From: Christine Ames [mailto:xxxxx@PacificDigital.com]
Sent: Wednesday, April 16, 2003 1:41 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

-----Original Message-----
From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Wednesday, April 16, 2003 12:55 PM


> (2) I don’t
> use anything in my service routines that’s not strictly ANSI
> C, so, I don’t
> depend on someone else’s headers

I’m Shocked! Shocked!

Dude. sprintf() IS ANSI C. Note the following from the standard
MSVC/C++
6.0 help:


sprintf, swprintf
Write formatted data to a string.

int sprintf( char *buffer, const char *format [, argument] … );
int swprintf( wchar_t *buffer, const wchar_t format [, argument] … );

Routine Required Header Compatibility
sprintf <stdio.h> ANSI, Win 95, Win NT
swprintf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT


Example

/
SPRINTF.C: This program uses sprintf to format various
* data and place them in the string named buffer.
/

#include <stdio.h>

void main( void )
{
char buffer[200], s[] = “computer”, c = ‘l’;
int i = 35, j;
float fp = 1.7320534f;

/
Format and print various data: */
j = sprintf( buffer, “\tString: %s\n”, s );
j += sprintf( buffer + j, “\tCharacter: %c\n”, c );
j += sprintf( buffer + j, “\tInteger: %d\n”, i );
j += sprintf( buffer + j, “\tReal: %f\n”, fp );

printf( “Output:\n%s\ncharacter count = %d\n”, buffer, j );
}

Output

Output:
String: computer
Character: l
Integer: 35
Real: 1.732053

character count = 71


You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</stdio.h></wchar.h></stdio.h></stdio.h>

A couple of things, yet first beware, I’m a minimalist. Before I did video
drivers for a living, I was a Bios programmer, so, you know where I’m coming
from ! I only use something if I’m forced to, and even then, I’ll only use
it screaming and kicking. My personal take on this is, and I don’t ask
anyone to follow me, Operating Systems and Runtime Libraries are there to be
bypassed: the best OS is the one I can take for granted and that doesn’t
stand on my way when I need to do something funky.

But on to specifics,

(1) This is Alberto speaking, not Compuware.
(2) I should have been more specific: I don’t like to use C libraries in
kernel code either.
(5) I have been using iostreams and cin/cout like stuff long enough that I
no longer care for printf and its relatives. And guess what, apart from a
few specific formats, I ignore the bulk of that functionality: I don’t need
it, and it’s been many moons since I last included stdio.h in my code.

And also, no, using sprintf doesn’t save time, not to me anyway: I wrote the
binary-to-ascii routine I emailed to you guys in less than a minute, and it
worked first time. Hence, why bother with sprintf ? It’s clunkier, it adds
lots of unused baggage, and it takes me longer to debug because it’s not my
code nor my semantics. Also, I can’t help to a feeling of writing dirty code
if I invoke a C library routine from inside one of my C++ classes. But then,
hey, that’s a personal thing.

Alberto.

-----Original Message-----
From: Mathieu Routhier [mailto:xxxxx@guillemot.com]
Sent: Wednesday, April 16, 2003 4:17 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

Mm let me think…

(1) It’s my code, and I trust my hand better than anyone else’s

Coming from the mouth of someone who pushes a certain driver framework
library, that statement seems contradictory.

(2) I don’t
use anything in my service routines that’s not strictly ANSI C, so, I don’t
depend on someone else’s headers,

sprintf() is ANSI C. Isn’t it?
http://www.lysator.liu.se/c/rat/d9.html#4-9-6-5

(5) I can write it an test it in way less
time it would take me to learn how sprintf works or what’s the semantics of
the Microsoft types.

I thought everyone who learned C/C++ was familiar with the printf()
function. Maybe I shouldn’t make that assumption? In any case, learning
sprintf() is definitely worth the effort: it will save you time every single
occasion where you need to format data into a string! You won’t even need
to write a special function. sprintf() must be the standard function I use
the most.

Mat

-----Original Message-----
From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Wednesday, April 16, 2003 3:55 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

Well…

(1) It’s my code, and I trust my hand better than anyone else’s, (2) I don’t
use anything in my service routines that’s not strictly ANSI C, so, I don’t
depend on someone else’s headers, (3) I can tailor it exactly to what I
need, (4) I can give my file a .cpp extension and take advantage of C++
features not available in C, and (5) I can write it an test it in way less
time it would take me to learn how sprintf works or what’s the semantics of
the Microsoft types.

It may be my own professional bias, but I like to minimize the number of
strings attached to my code !

Alberto.

-----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 driver

What’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@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@guillemot.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


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.</stdio.h>

Like I pointed out to Mathieu, I should have been more specific. I don’t
like to use C library calls in my kernel code either, I feel that my code is
dirty if it needs to call something like sprintf from within one of my
classes. The reason why I mentioned Ansi C is that I don’t like to use
things such as LONG, ULONG, PSTRING and what not, as opposed to the standard
C++ types. I do it when there’s no other way, but I avoid it whenever I can.

Alberto.

-----Original Message-----
From: Christine Ames [mailto:xxxxx@PacificDigital.com]
Sent: Wednesday, April 16, 2003 4:41 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

-----Original Message-----
From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Wednesday, April 16, 2003 12:55 PM


> (2) I don’t
> use anything in my service routines that’s not strictly ANSI
> C, so, I don’t
> depend on someone else’s headers

I’m Shocked! Shocked!

Dude. sprintf() IS ANSI C. Note the following from the standard MSVC/C++
6.0 help:


sprintf, swprintf
Write formatted data to a string.

int sprintf( char *buffer, const char *format [, argument] … );
int swprintf( wchar_t *buffer, const wchar_t format [, argument] … );

Routine Required Header Compatibility
sprintf <stdio.h> ANSI, Win 95, Win NT
swprintf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT


Example

/
SPRINTF.C: This program uses sprintf to format various
* data and place them in the string named buffer.
/

#include <stdio.h>

void main( void )
{
char buffer[200], s[] = “computer”, c = ‘l’;
int i = 35, j;
float fp = 1.7320534f;

/
Format and print various data: */
j = sprintf( buffer, “\tString: %s\n”, s );
j += sprintf( buffer + j, “\tCharacter: %c\n”, c );
j += sprintf( buffer + j, “\tInteger: %d\n”, i );
j += sprintf( buffer + j, “\tReal: %f\n”, fp );

printf( “Output:\n%s\ncharacter count = %d\n”, buffer, j );
}

Output

Output:
String: computer
Character: l
Integer: 35
Real: 1.732053

character count = 71


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.</stdio.h></wchar.h></stdio.h></stdio.h>

To add to that, there is also ntstrsafe.h, which returns NTSTATUS codes
instead of COM’ish HRESULTs (although either are usable from a driver).

D

This posting is provided “AS IS” with no warranties, and confers no
rights.

-----Original Message-----
From: Mike Tricker [mailto:xxxxx@microsoft.com]
Sent: Wednesday, April 16, 2003 1:47 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

For anyone considering string manipulation of this sort may I strongly
encourage you to check out strsafe.h that lives in the DDK under
inc\crt.

You’ll find alternatives to the standard CRT string manipulation
functions that help avoid some of the common pitfalls we see with string
manipulation (buffer overruns etc.), all of which were developed as part
of the Windows security initiative last year.

Please let us know if you have feedback - positive or negative!

= Mike =

This posting is provided “AS IS” with no warranties, and confers no
rights

-----Original Message-----
From: Christine Ames [mailto:xxxxx@PacificDigital.com]
Sent: Wednesday, April 16, 2003 1:41 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

-----Original Message-----
From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Wednesday, April 16, 2003 12:55 PM


> (2) I don’t
> use anything in my service routines that’s not strictly ANSI
> C, so, I don’t
> depend on someone else’s headers

I’m Shocked! Shocked!

Dude. sprintf() IS ANSI C. Note the following from the standard
MSVC/C++
6.0 help:


sprintf, swprintf
Write formatted data to a string.

int sprintf( char *buffer, const char *format [, argument] … );
int swprintf( wchar_t *buffer, const wchar_t format [, argument] … );

Routine Required Header Compatibility
sprintf <stdio.h> ANSI, Win 95, Win NT
swprintf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT


Example

/
SPRINTF.C: This program uses sprintf to format various
* data and place them in the string named buffer.
/

#include <stdio.h>

void main( void )
{
char buffer[200], s[] = “computer”, c = ‘l’;
int i = 35, j;
float fp = 1.7320534f;

/
Format and print various data: */
j = sprintf( buffer, “\tString: %s\n”, s );
j += sprintf( buffer + j, “\tCharacter: %c\n”, c );
j += sprintf( buffer + j, “\tInteger: %d\n”, i );
j += sprintf( buffer + j, “\tReal: %f\n”, fp );

printf( “Output:\n%s\ncharacter count = %d\n”, buffer, j );
}

Output

Output:
String: computer
Character: l
Integer: 35
Real: 1.732053

character count = 71


You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</stdio.h></wchar.h></stdio.h></stdio.h>

Mike,

it seems well at first look. What I’m missing is the info about safe IRQ
levels where these functions can be used. I presume some are safe at
DISPATCH_LEVEL as far as nonpaged memory is used for buffers and some may
not be as sprintf replacements using unicode formats. However, this info is
essential for kernel mode developers and should be provided.

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


From: xxxxx@microsoft.com[SMTP:xxxxx@microsoft.com]
Reply To: xxxxx@lists.osr.com
Sent: Wednesday, April 16, 2003 10:47 PM
To: xxxxx@lists.osr.com
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

For anyone considering string manipulation of this sort may I strongly
encourage you to check out strsafe.h that lives in the DDK under
inc\crt.

You’ll find alternatives to the standard CRT string manipulation
functions that help avoid some of the common pitfalls we see with string
manipulation (buffer overruns etc.), all of which were developed as part
of the Windows security initiative last year.

Please let us know if you have feedback - positive or negative!

= Mike =

This posting is provided “AS IS” with no warranties, and confers no
rights

But better to use the functions found in NTSTRSAFE.H and NTSTRSAFE.LIB.

char SzGuidToPrint[GUID_SIZE];
NTSTATUS status;

status = RtlStringCchPrintfW(SzGuidToPrint, sizeof(SzGuidToPrint), L"%08lx",
Guid.Data1);

Read next months article in Windows Driver Developers Digest.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Jamey Kirby” wrote in message news:xxxxx@ntdev…
>
> Enough sarcasm; I guess…
>
> I think he may be looking for ACII character representation of a number
> like 100 -> “100” for a printable string or something.
>
> You can do it the hard way or you can use various sprintf like functions
> to do the formatting for you.
>
> In some of our drivers, we have code like this:
>
> swprintf(SzGuidToPrint, L"%08lx", Guid.Data1);
>
> where SzGuidToPrint is a string representation of the value.
>
> Jamey
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Jamey Kirby
> Sent: Tuesday, April 15, 2003 5:21 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
>
> Does it matter :slight_smile:
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Justin Frodsham
> Sent: Tuesday, April 15, 2003 5:00 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
>
> I am not certain you have supplied enough information answer the
> question. What are you trying to do? ASCII can be represented by an
> 8bit
> binary/hex value… So I don’t understand what you are trying to
> convert
> from/to.
>
> -Justin
>
> At 01:36 PM 4/15/2003, you wrote:
> >Hi All,
> >
> >How should I convert my 8 bit binary/Hex value to
> >corresponding ASCII in my device driver.
> >
> >
> > __________________________________________________
> >Do you Yahoo!?
> >The New Yahoo! Search - Faster. Easier. Bingo
> >http://search.yahoo.com
> >
> >
> >—
> >You are currently subscribed to ntdev as: zeppelin@io.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>

Justin … don’t be silly … FORTH is always the language of choice.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Justin Frodsham” wrote in message news:xxxxx@ntdev…
>
> Very funny… first though… if you want to write a really good
> driver you need to use LOGO as your programming language. VB is way too
> low level.
>
> -J
>
> At 03:34 PM 4/15/2003, you wrote:
> >I want to write an encrypting file system driver. I have written
> >several hello world programs in VB before. What do I need to know to do
> >this?
> >
> >Thanks,
> >Rob
> >
> >
> >
> >
> >:)
> >
> >-----Original Message-----
> >From: xxxxx@lists.osr.com
> >[mailto:xxxxx@lists.osr.com] On Behalf Of Justin Frodsham
> >Sent: Tuesday, April 15, 2003 8:06 PM
> >To: NT Developers Interest List
> >Subject: [ntdev] RE: Binary/Hex to ASCII conversion in driver
> >
> >Are there any of us here that have not asked a dumb question at some
> >point
> >in life??.. Were you born with computer knowledge or did you have to
> >
> >learn like the rest of us?
> >
> >-Justin
> >
> >At 01:58 PM 4/15/2003, you wrote:
> > >My apologies, there are no stupid questions; only inquisitive idiots.
> > >
> > >Jamey
> > >
> > >
> > >-----Original Message-----
> > >From: xxxxx@lists.osr.com
> > >[mailto:xxxxx@lists.osr.com] On Behalf Of Tom Pr
> > >Sent: Tuesday, April 15, 2003 4:36 PM
> > >To: NT Developers Interest List
> > >Subject: [ntdev] Binary/Hex to ASCII conversion in driver
> > >
> > >Hi All,
> > >
> > >How should I convert my 8 bit binary/Hex value to
> > >corresponding ASCII in my device driver.
> > >
> > >
> > > __________________________________________________
> > >Do you Yahoo!?
> > >The New Yahoo! Search - Faster. Easier. Bingo
> > >http://search.yahoo.com
> > >
> > >
> > >—
> > >You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> > >To unsubscribe send a blank email to xxxxx@lists.osr.com
> > >
> > >
> > >
> > >—
> > >You are currently subscribed to ntdev as: zeppelin@io.com
> > >To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
> >
> >
> >—
> >You are currently subscribed to ntdev as: xxxxx@cdp.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
> >—
> >You are currently subscribed to ntdev as: zeppelin@io.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
>

Be vewy vewy quiet … we are chasing wabbits …

Gary

“Roddy, Mark” wrote in message news:xxxxx@ntdev…
>
> shhhhh… they are busy reinventing the wheel discovering the obvious,
> leave them alone.
>

But Alberto you use C … hell … you use assembly … you use SI … you
don’t sit there with a switch lite panel and toggle in every frigging
instruction and hit run … to toggle in the NEXT frigging instruction and
hit run … to toggle in the NEXT frigging instruction and hit run … to
toggle in the NEXT frigging instruction and hit run … to toggle in the
NEXT frigging instruction and hit run … to toggle in the NEXT frigging
instruction and hit run … to toggle in the NEXT frigging instruction and
hit run … to toggle in the NEXT frigging instruction and hit run … to
toggle in the NEXT frigging instruction and hit run … to toggle in the
NEXT frigging instruction and hit run … to toggle in the NEXT frigging
instruction and hit run … to toggle in the NEXT frigging instruction and
hit run … to toggle in the NEXT frigging instruction and hit run … to
toggle in the NEXT frigging instruction and hit run … to toggle in the
NEXT frigging instruction and hit run … to toggle in the NEXT frigging
instruction and hit run … to toggle in the NEXT frigging instruction and
hit run … to toggle in the NEXT frigging instruction and hit run … to
toggle in the NEXT frigging instruction and hit run … to toggle in the
NEXT frigging instruction and hit run … to toggle in the NEXT frigging
instruction and hit run … to toggle in the NEXT frigging instruction and
hit run … to toggle in the NEXT frigging instruction and hit run … to
toggle in the NEXT frigging instruction and hit run … to toggle in the
NEXT frigging instruction and hit run … to toggle in the NEXT frigging
instruction and hit run … to toggle in the NEXT frigging instruction and
hit run … to toggle in the NEXT frigging instruction and hit run … to
toggle in the NEXT frigging instruction and hit run … to toggle in the
NEXT frigging instruction and hit run … to toggle in the NEXT frigging
instruction and hit run … to toggle in the NEXT frigging instruction and
hit run … to toggle in the NEXT frigging instruction and hit run … to
toggle in the NEXT frigging instruction and hit run … to toggle in the
NEXT frigging instruction and hit run … to toggle in the NEXT frigging
instruction and hit run

:slight_smile:

well … you might … but I’d rather use a compiler and the tools
avaliable.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Moreira, Alberto” wrote in message
news:xxxxx@ntdev…
>
> Well…
>
> (1) It’s my code, and I trust my hand better than anyone else’s, (2) I
don’t
> use anything in my service routines that’s not strictly ANSI C, so, I
don’t
> depend on someone else’s headers, (3) I can tailor it exactly to what I
> need, (4) I can give my file a .cpp extension and take advantage of C++
> features not available in C, and (5) I can write it an test it in way less
> time it would take me to learn how sprintf works or what’s the semantics
of
> the Microsoft types.
>
> It may be my own professional bias, but I like to minimize the number of
> strings attached to my code !
>
> Alberto.
>
>
>
> -----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 driver
>
>
> What’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@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.
>
>
>
></stdio.h>

I looked in the WNET DDK help file and the header file and couldn’t find any
reference to IRQL. I think they need to tell us about any restrictions even
if there are none.

----- Original Message -----
From: “Michal Vodicka”
To: “NT Developers Interest List”
Sent: Wednesday, April 16, 2003 5:32 PM
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

> Mike,
>
> it seems well at first look. What I’m missing is the info about safe IRQ
> levels where these functions can be used. I presume some are safe at
> DISPATCH_LEVEL as far as nonpaged memory is used for buffers and some may
> not be as sprintf replacements using unicode formats. However, this info
is
> essential for kernel mode developers and should be provided.
>
> Best regards,
>
> Michal Vodicka
> STMicroelectronics Design and Application s.r.o.
> [michal.vodicka@st.com, http:://www.st.com]
>
> > ----------
> > From: xxxxx@microsoft.com[SMTP:xxxxx@microsoft.com]
> > Reply To: xxxxx@lists.osr.com
> > Sent: Wednesday, April 16, 2003 10:47 PM
> > To: xxxxx@lists.osr.com
> > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> >
> > For anyone considering string manipulation of this sort may I strongly
> > encourage you to check out strsafe.h that lives in the DDK under
> > inc\crt.
> >
> > You’ll find alternatives to the standard CRT string manipulation
> > functions that help avoid some of the common pitfalls we see with string
> > manipulation (buffer overruns etc.), all of which were developed as part
> > of the Windows security initiative last year.
> >
> > Please let us know if you have feedback - positive or negative!
> >
> > = Mike =
> >
> > This posting is provided “AS IS” with no warranties, and confers no
> > rights
> >
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@yoshimuni.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Michal,

That depends on where the buffers are. If in nonpaged memory you can use
them > DISPATCH, and if in paged then thou shalt not exceed nor be equal to
DISPATCH.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Michal Vodicka” wrote in message
news:xxxxx@ntdev…
>
> Mike,
>
> it seems well at first look. What I’m missing is the info about safe IRQ
> levels where these functions can be used. I presume some are safe at
> DISPATCH_LEVEL as far as nonpaged memory is used for buffers and some may
> not be as sprintf replacements using unicode formats. However, this info
is
> essential for kernel mode developers and should be provided.
>
> Best regards,
>
> Michal Vodicka
> STMicroelectronics Design and Application s.r.o.
> [michal.vodicka@st.com, http:://www.st.com]
>
> > ----------
> > From: xxxxx@microsoft.com[SMTP:xxxxx@microsoft.com]
> > Reply To: xxxxx@lists.osr.com
> > Sent: Wednesday, April 16, 2003 10:47 PM
> > To: xxxxx@lists.osr.com
> > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> >
> > For anyone considering string manipulation of this sort may I strongly
> > encourage you to check out strsafe.h that lives in the DDK under
> > inc\crt.
> >
> > You’ll find alternatives to the standard CRT string manipulation
> > functions that help avoid some of the common pitfalls we see with string
> > manipulation (buffer overruns etc.), all of which were developed as part
> > of the Windows security initiative last year.
> >
> > Please let us know if you have feedback - positive or negative!
> >
> > = Mike =
> >
> > This posting is provided “AS IS” with no warranties, and confers no
> > rights
> >
>
>
>

Gary,

yes, but there can still be a problem with NLS tables loaded in paged memory
and you have a problem even if all your buffers are nonpaged. The same
problem as swprintf or DbgPrint with %wZ have. I presume it is possible to
judge which functions are safe and which aren’t but still believe this info
should be provided. That’s whole point.

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


From: xxxxx@aerosurf.net[SMTP:xxxxx@aerosurf.net]
Reply To: xxxxx@lists.osr.com
Sent: Thursday, April 17, 2003 1:14 AM
To: xxxxx@lists.osr.com
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

Michal,

That depends on where the buffers are. If in nonpaged memory you can use
them > DISPATCH, and if in paged then thou shalt not exceed nor be equal
to
DISPATCH.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Michal Vodicka” wrote in message
> news:xxxxx@ntdev…
> >
> > Mike,
> >
> > it seems well at first look. What I’m missing is the info about safe IRQ
> > levels where these functions can be used. I presume some are safe at
> > DISPATCH_LEVEL as far as nonpaged memory is used for buffers and some
> may
> > not be as sprintf replacements using unicode formats. However, this info
> is
> > essential for kernel mode developers and should be provided.
> >
> > Best regards,
> >
> > Michal Vodicka
> > STMicroelectronics Design and Application s.r.o.
> > [michal.vodicka@st.com, http:://www.st.com]
> >
> > > ----------
> > > From: xxxxx@microsoft.com[SMTP:xxxxx@microsoft.com]
> > > Reply To: xxxxx@lists.osr.com
> > > Sent: Wednesday, April 16, 2003 10:47 PM
> > > To: xxxxx@lists.osr.com
> > > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> > >
> > > For anyone considering string manipulation of this sort may I strongly
> > > encourage you to check out strsafe.h that lives in the DDK under
> > > inc\crt.
> > >
> > > You’ll find alternatives to the standard CRT string manipulation
> > > functions that help avoid some of the common pitfalls we see with
> string
> > > manipulation (buffer overruns etc.), all of which were developed as
> part
> > > of the Windows security initiative last year.
> > >
> > > Please let us know if you have feedback - positive or negative!
> > >
> > > = Mike =
> > >
> > > This posting is provided “AS IS” with no warranties, and confers no
> > > rights
> > >
> >
> >
> >
>
>
>
> —
> You are currently subscribed to ntdev as: michal.vodicka@st.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

David,

The functions do nothing really other than move the contents of a buffer to
another buffer. Given this then the IRQL should not exceed the max IRQL you
can access a given buffer.

One caveate … the RtlStringCch/CbPrintfA/W functions use a call to
_vsprintf. Now it may be true that they can used at or above DISPATCH, I
don’t believe it is a good practice.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“David J. Craig” wrote in message
news:xxxxx@ntdev…
>
> I looked in the WNET DDK help file and the header file and couldn’t find
any
> reference to IRQL. I think they need to tell us about any restrictions
even
> if there are none.
>
> ----- Original Message -----
> From: “Michal Vodicka”
> To: “NT Developers Interest List”
> Sent: Wednesday, April 16, 2003 5:32 PM
> Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
>
>
> > Mike,
> >
> > it seems well at first look. What I’m missing is the info about safe IRQ
> > levels where these functions can be used. I presume some are safe at
> > DISPATCH_LEVEL as far as nonpaged memory is used for buffers and some
may
> > not be as sprintf replacements using unicode formats. However, this info
> is
> > essential for kernel mode developers and should be provided.
> >
> > Best regards,
> >
> > Michal Vodicka
> > STMicroelectronics Design and Application s.r.o.
> > [michal.vodicka@st.com, http:://www.st.com]
> >
> > > ----------
> > > From: xxxxx@microsoft.com[SMTP:xxxxx@microsoft.com]
> > > Reply To: xxxxx@lists.osr.com
> > > Sent: Wednesday, April 16, 2003 10:47 PM
> > > To: xxxxx@lists.osr.com
> > > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> > >
> > > For anyone considering string manipulation of this sort may I strongly
> > > encourage you to check out strsafe.h that lives in the DDK under
> > > inc\crt.
> > >
> > > You’ll find alternatives to the standard CRT string manipulation
> > > functions that help avoid some of the common pitfalls we see with
string
> > > manipulation (buffer overruns etc.), all of which were developed as
part
> > > of the Windows security initiative last year.
> > >
> > > Please let us know if you have feedback - positive or negative!
> > >
> > > = Mike =
> > >
> > > This posting is provided “AS IS” with no warranties, and confers no
> > > rights
> > >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@yoshimuni.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
>
>
>
>
>

But doesn’t that relate more to a sync/serial problem and not a pure IRQL
level?


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Michal Vodicka” wrote in message
news:xxxxx@ntdev…
>
> Gary,
>
> yes, but there can still be a problem with NLS tables loaded in paged
memory
> and you have a problem even if all your buffers are nonpaged. The same
> problem as swprintf or DbgPrint with %wZ have. I presume it is possible to
> judge which functions are safe and which aren’t but still believe this
info
> should be provided. That’s whole point.
>
> Best regards,
>
> Michal Vodicka
> STMicroelectronics Design and Application s.r.o.
> [michal.vodicka@st.com, http:://www.st.com]
>
> > ----------
> > From: xxxxx@aerosurf.net[SMTP:xxxxx@aerosurf.net]
> > Reply To: xxxxx@lists.osr.com
> > Sent: Thursday, April 17, 2003 1:14 AM
> > To: xxxxx@lists.osr.com
> > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> >
> > Michal,
> >
> > That depends on where the buffers are. If in nonpaged memory you can use
> > them > DISPATCH, and if in paged then thou shalt not exceed nor be equal
> > to
> > DISPATCH.
> >
> > –
> > Gary G. Little
> > Have Computer, Will Travel …
> > 909-698-3191
> > 909-551-2105
> > http://www.wd-3.com
> >
> > “Michal Vodicka” wrote in message
> > news:xxxxx@ntdev…
> > >
> > > Mike,
> > >
> > > it seems well at first look. What I’m missing is the info about safe
IRQ
> > > levels where these functions can be used. I presume some are safe at
> > > DISPATCH_LEVEL as far as nonpaged memory is used for buffers and some
> > may
> > > not be as sprintf replacements using unicode formats. However, this
info
> > is
> > > essential for kernel mode developers and should be provided.
> > >
> > > Best regards,
> > >
> > > Michal Vodicka
> > > STMicroelectronics Design and Application s.r.o.
> > > [michal.vodicka@st.com, http:://www.st.com]
> > >
> > > > ----------
> > > > From: xxxxx@microsoft.com[SMTP:xxxxx@microsoft.com]
> > > > Reply To: xxxxx@lists.osr.com
> > > > Sent: Wednesday, April 16, 2003 10:47 PM
> > > > To: xxxxx@lists.osr.com
> > > > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> > > >
> > > > For anyone considering string manipulation of this sort may I
strongly
> > > > encourage you to check out strsafe.h that lives in the DDK under
> > > > inc\crt.
> > > >
> > > > You’ll find alternatives to the standard CRT string manipulation
> > > > functions that help avoid some of the common pitfalls we see with
> > string
> > > > manipulation (buffer overruns etc.), all of which were developed as
> > part
> > > > of the Windows security initiative last year.
> > > >
> > > > Please let us know if you have feedback - positive or negative!
> > > >
> > > > = Mike =
> > > >
> > > > This posting is provided “AS IS” with no warranties, and confers no
> > > > rights
> > > >
> > >
> > >
> > >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: michal.vodicka@st.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
>

No, this is IRQL problem. NLS tables are accessed internally by string
conversion routines which can be called during string formating. They can be
paged out and you know what it means. The problem is hard to find because
they are used frequently and mostly paged in so driver “works”. And crashes
production server later (my very old experience :). Checked build catches it
correctly (failed assertion). That’s why for example
RtlUnicodeStringToAnsiString() may be called at PASSIVE_LEVEL only even if
all buffers are nonpaged.

Well, it is based on old experiences and I’m not sure if something wasn’t
changed in XP and above. That’s why it should be documented carefully.

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


From: xxxxx@aerosurf.net[SMTP:xxxxx@aerosurf.net]
Reply To: xxxxx@lists.osr.com
Sent: Thursday, April 17, 2003 2:55 AM
To: xxxxx@lists.osr.com
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

But doesn’t that relate more to a sync/serial problem and not a pure IRQL
level?


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105
http://www.wd-3.com

“Michal Vodicka” wrote in message
> news:xxxxx@ntdev…
> >
> > Gary,
> >
> > yes, but there can still be a problem with NLS tables loaded in paged
> memory
> > and you have a problem even if all your buffers are nonpaged. The same
> > problem as swprintf or DbgPrint with %wZ have. I presume it is possible
> to
> > judge which functions are safe and which aren’t but still believe this
> info
> > should be provided. That’s whole point.
> >
> > Best regards,
> >
> > Michal Vodicka
> > STMicroelectronics Design and Application s.r.o.
> > [michal.vodicka@st.com, http:://www.st.com]
> >
> > > ----------
> > > From: xxxxx@aerosurf.net[SMTP:xxxxx@aerosurf.net]
> > > Reply To: xxxxx@lists.osr.com
> > > Sent: Thursday, April 17, 2003 1:14 AM
> > > To: xxxxx@lists.osr.com
> > > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> > >
> > > Michal,
> > >
> > > That depends on where the buffers are. If in nonpaged memory you can
> use
> > > them > DISPATCH, and if in paged then thou shalt not exceed nor be
> equal
> > > to
> > > DISPATCH.
> > >
> > > –
> > > Gary G. Little
> > > Have Computer, Will Travel …
> > > 909-698-3191
> > > 909-551-2105
> > > http://www.wd-3.com
> > >
> > > “Michal Vodicka” wrote in message
> > > news:xxxxx@ntdev…
> > > >
> > > > Mike,
> > > >
> > > > it seems well at first look. What I’m missing is the info about safe
> IRQ
> > > > levels where these functions can be used. I presume some are safe at
> > > > DISPATCH_LEVEL as far as nonpaged memory is used for buffers and
> some
> > > may
> > > > not be as sprintf replacements using unicode formats. However, this
> info
> > > is
> > > > essential for kernel mode developers and should be provided.
> > > >
> > > > Best regards,
> > > >
> > > > Michal Vodicka
> > > > STMicroelectronics Design and Application s.r.o.
> > > > [michal.vodicka@st.com, http:://www.st.com]
> > > >
> > > > > ----------
> > > > > From: xxxxx@microsoft.com[SMTP:xxxxx@microsoft.com]
> > > > > Reply To: xxxxx@lists.osr.com
> > > > > Sent: Wednesday, April 16, 2003 10:47 PM
> > > > > To: xxxxx@lists.osr.com
> > > > > Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
> > > > >
> > > > > For anyone considering string manipulation of this sort may I
> strongly
> > > > > encourage you to check out strsafe.h that lives in the DDK under
> > > > > inc\crt.
> > > > >
> > > > > You’ll find alternatives to the standard CRT string manipulation
> > > > > functions that help avoid some of the common pitfalls we see with
> > > string
> > > > > manipulation (buffer overruns etc.), all of which were developed
> as
> > > part
> > > > > of the Windows security initiative last year.
> > > > >
> > > > > Please let us know if you have feedback - positive or negative!
> > > > >
> > > > > = Mike =
> > > > >
> > > > > This posting is provided “AS IS” with no warranties, and confers
> no
> > > > > rights
> > > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as: michal.vodicka@st.com
> > > To unsubscribe send a blank email to xxxxx@lists.osr.com
> > >
> >
> >
> >
>
>
>
> —
> You are currently subscribed to ntdev as: michal.vodicka@st.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

You use and like C++ but you do not trust anyone else’s code; something
is not right here :slight_smile:

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Wednesday, April 16, 2003 12:55 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver

Well…

(1) It’s my code, and I trust my hand better than anyone else’s, (2) I
don’t
use anything in my service routines that’s not strictly ANSI C, so, I
don’t
depend on someone else’s headers, (3) I can tailor it exactly to what I
need, (4) I can give my file a .cpp extension and take advantage of C++
features not available in C, and (5) I can write it an test it in way
less
time it would take me to learn how sprintf works or what’s the semantics
of
the Microsoft types.

It may be my own professional bias, but I like to minimize the number of
strings attached to my code !

Alberto.

-----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 driver

What’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@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@storagecraft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</stdio.h>