I think you are using C++ for the wrong reasons then.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Wednesday, April 16, 2003 1:50 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Binary/Hex to ASCII conversion in driver
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.
—
You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</stdio.h>