converting char* into BYTE*
-
Hi, how to conver char* into BYTE* in C++ Regards
-
Hi, how to conver char* into BYTE* in C++ Regards
Short (and dangerous) answer: with a cast, for instance
char * myCharPointer ="hello";
BYTE * myBytePointer = (BYTE *) myCharPointer;A better answer may follow a more detailed request. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, how to conver char* into BYTE* in C++ Regards
Something like:
BYTE* pByte = reinterpretcast< BYTE* >( pChar );
"The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)
-
Something like:
BYTE* pByte = reinterpretcast< BYTE* >( pChar );
"The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)
Matthew Faithfull wrote:
BYTE* pByte = reinterpretcast< BYTE* >( pChar );
quite...
reinterpret_cast
is the correct word ^^ BTW, i didn't try, but wouldn'tstatic_cast
just work here ?[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Short (and dangerous) answer: with a cast, for instance
char * myCharPointer ="hello";
BYTE * myBytePointer = (BYTE *) myCharPointer;A better answer may follow a more detailed request. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]of course, you're looking for devil every where :p a char* is not always a string ;)
char c = 'c';
char* pc = &c;BYTE* pb1 = (BYTE*)pc;
BYTE* pb2 = reinterpret_cast<BYTE*>(pc);BTW, looking at the level of the question, i think it's worth saying that a
char
IS aBYTE
:char c = 'c';
BYTE b = c;
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
of course, you're looking for devil every where :p a char* is not always a string ;)
char c = 'c';
char* pc = &c;BYTE* pb1 = (BYTE*)pc;
BYTE* pb2 = reinterpret_cast<BYTE*>(pc);BTW, looking at the level of the question, i think it's worth saying that a
char
IS aBYTE
:char c = 'c';
BYTE b = c;
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
a char* is not always a string
char* is never a string. :laugh:
-
toxcct wrote:
a char* is not always a string
char* is never a string. :laugh:
what do you know about C++, you Mr univoter ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
what do you know about C++, you Mr univoter ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
nice arguments :laugh:
-
Matthew Faithfull wrote:
BYTE* pByte = reinterpretcast< BYTE* >( pChar );
quite...
reinterpret_cast
is the correct word ^^ BTW, i didn't try, but wouldn'tstatic_cast
just work here ?[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
Right you are, I knew that looked wrong somehow. I don't think static_cast works on pointers even when there are in fact a type match as these probably would be. Would have to try it to be sure.
"The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)
-
Hi, how to conver char* into BYTE* in C++ Regards
A BYTE is nothing but an unsigned char. If you do the math, that would tell you that the conversion may result in data loss, depending on the value stored in the char variable. The following situation may be an example:
char p = -23;
int i; // if you assign p to i, you'll not lose data.
BYTE b; // if you assign p to b, you'll lose data.Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
-
Matthew Faithfull wrote:
BYTE* pByte = reinterpretcast< BYTE* >( pChar );
quite...
reinterpret_cast
is the correct word ^^ BTW, i didn't try, but wouldn'tstatic_cast
just work here ?[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
BTW, i didn't try, but wouldn't static_cast just work here ?
A static_cast won't work.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
-
A BYTE is nothing but an unsigned char. If you do the math, that would tell you that the conversion may result in data loss, depending on the value stored in the char variable. The following situation may be an example:
char p = -23;
int i; // if you assign p to i, you'll not lose data.
BYTE b; // if you assign p to b, you'll lose data.Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
To be very picky you don't actually loose data, as it's still an 8-bit value. It's just that the semantics change, your -23 = 11101001 gets reinterpretted as 233 = 11101001. :)
"The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)
-
To be very picky you don't actually loose data, as it's still an 8-bit value. It's just that the semantics change, your -23 = 11101001 gets reinterpretted as 233 = 11101001. :)
"The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)
[Footer: not for nitpicks, but for the noob op] :laugh:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
-
of course, you're looking for devil every where :p a char* is not always a string ;)
char c = 'c';
char* pc = &c;BYTE* pb1 = (BYTE*)pc;
BYTE* pb2 = reinterpret_cast<BYTE*>(pc);BTW, looking at the level of the question, i think it's worth saying that a
char
IS aBYTE
:char c = 'c';
BYTE b = c;
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
of course, you're looking for devil every where [Poke tongue]
of course. :)
toxcct wrote:
BTW, looking at the level of the question, i think it's worth saying that a char IS a BYTE:
Nope. As you know (I know that you know ;) ),
char
is a signed integer ranging from-128
to127
, while aBYTE
is an unsigned integer ranging from0
to255
. ;PIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
toxcct wrote:
of course, you're looking for devil every where [Poke tongue]
of course. :)
toxcct wrote:
BTW, looking at the level of the question, i think it's worth saying that a char IS a BYTE:
Nope. As you know (I know that you know ;) ),
char
is a signed integer ranging from-128
to127
, while aBYTE
is an unsigned integer ranging from0
to255
. ;PIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]but you're already going to far by interpreting the bits pattern. a BYTE is 8 bits, which is exactly what a char is supposed to be too. ;)
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
but you're already going to far by interpreting the bits pattern. a BYTE is 8 bits, which is exactly what a char is supposed to be too. ;)
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
but you're already going to far by interpreting the bits pattern.
Duty sir, duty. :rolleyes:
toxcct wrote:
a BYTE is 8 bits, which is exactly what a char is supposed to be too.
float
andint
(evenpointers
!) have the same size on32
bit systems but we usually don't consider them being the same. :-DIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]