I try to put 8 int bit for example 10100010 into one character of type
char(1 octet) with no hope . Could anyone propose a simple way to do
it? Thank you very much. 13 2745
Anna <pe*********@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of type
char(1 octet) with no hope . Could anyone propose a simple way to do
it? Thank you very much.
It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing.
--
Ben.
On 15 juin, 11:52, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
Anna <petitmou...@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of type
char(1 octet) with no hope . Could anyone propose a simple way to do
it? Thank you very much.
It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing.
--
Ben.
thank you Ben. I have bit sequence 01010101.... that I want to
implement into a simulator, but in the simulator, they use a char as a
type of data since each int comprise between 2-4 octet and one char is
only 1 octet (=8 bits 0 or 1). I guess it will make the simulator run
faster, I'm not sure.
Anna <pe*********@gmail.comwrites:
On 15 juin, 11:52, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
>Anna <petitmou...@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of type
char(1 octet) with no hope . Could anyone propose a simple way to do
it? Thank you very much.
It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing.
-- Ben.
Best not quote sig blocks.
thank you Ben. I have bit sequence 01010101.... that I want to
implement into a simulator, but in the simulator, they use a char as a
type of data since each int comprise between 2-4 octet and one char is
only 1 octet (=8 bits 0 or 1). I guess it will make the simulator run
faster, I'm not sure.
For your information, in C a char is not always an octet and there are
systems where the sizes of the various types can be quite surprising.
I don't think that affects your question, though.
I can't tell if I answered your question. If I did not, you need to
give much more information. Some actual code is often the best way
for people here to see what the problem is.
--
Ben.
On 15 juin, 12:20, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
Anna <petitmou...@gmail.comwrites:
On 15 juin, 11:52, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
Anna <petitmou...@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of type
char(1 octet) with no hope . Could anyone propose a simple way to do
it? Thank you very much.
It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing.
--
Ben.
Best not quote sig blocks.
thank you Ben. I have bit sequence 01010101.... that I want to
implement into a simulator, but in the simulator, they use a char as a
type of data since each int comprise between 2-4 octet and one char is
only 1 octet (=8 bits 0 or 1). I guess it will make the simulator run
faster, I'm not sure.
For your information, in C a char is not always an octet and there are
systems where the sizes of the various types can be quite surprising.
I don't think that affects your question, though.
I can't tell if I answered your question. If I did not, you need to
give much more information. Some actual code is often the best way
for people here to see what the problem is.
--
Ben.
I think I'll have to try to understand the simulator first. it's a
very complicate network simulator with lots of code :-(. I will try to
implement what you suggested and will post the code if I have further
information. thank you very much.
Hi
On Sun, 15 Jun 2008 03:00:50 -0700, Anna wrote:
On 15 juin, 11:52, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
>Anna <petitmou...@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of
type char(1 octet) with no hope . Could anyone propose a simple way
to do it? Thank you very much.
It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing.
thank you Ben. I have bit sequence 01010101.... that I want to implement
into a simulator, but in the simulator, they use a char as a type of
data since each int comprise between 2-4 octet and one char is only 1
octet (=8 bits 0 or 1). I guess it will make the simulator run faster,
I'm not sure.
Do you mean that you have eight integers but that each one has either the
value 1 or 0? In that case, do:
Est-ce que vous-voulez dire que vous avez huite integers et que chaqun
d'entre eux a le valeur 1 ou 0? En ce cas, faitez:
int integers[8];
unsigned char character;
character= ( integers[0] ? (1 << 0) : 0 )
| ( integers[1] ? (1 << 1) : 0 )
| ( integers[2] ? (1 << 2) : 0 )
| ( integers[3] ? (1 << 3) : 0 )
| ( integers[4] ? (1 << 4) : 0 )
| ( integers[5] ? (1 << 5) : 0 )
| ( integers[6] ? (1 << 6) : 0 )
| ( integers[7] ? (1 << 7) : 0 );
Actually this works if the integers have the value 0 or non-0. If you
are certain that they can only be 1 or 0, the following may be faster:
Ceci marche si les integers ont les valeurs 0 ou non-0. Si vous etez
certain que ils n'ont que 1 ou 0, le ci-dessus peut-etre plus vite:
character= (integers[0] << 0)
| ( integers[1] << 1)
| ( integers[2] << 2)
| ( integers[3] << 3)
| ( integers[4] << 4)
| ( integers[5] << 5)
| ( integers[6] << 6)
| ( integers[7] << 7);
HTH
viza
viza wrote:
Anna wrote:
>Ben Bacarisse <ben.use...@bsb.me.ukwrote:
>>Anna <petitmou...@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of type char(1 octet) with no hope . Could anyone propose a simple way to do it? Thank you very much.
It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing.
thank you Ben. I have bit sequence 01010101.... that I want to implement into a simulator, but in the simulator, they use a char as a type of data since each int comprise between 2-4 octet and one char is only 1 octet (=8 bits 0 or 1). I guess it will make the simulator run faster, I'm not sure.
Do you mean that you have eight integers but that each one has
either the value 1 or 0? In that case, do:
Est-ce que vous-voulez dire que vous avez huite integers et que
chaqun d'entre eux a le valeur 1 ou 0? En ce cas, faitez:
int integers[8];
unsigned char character;
character= ( integers[0] ? (1 << 0) : 0 )
| ( integers[1] ? (1 << 1) : 0 )
| ( integers[2] ? (1 << 2) : 0 )
| ( integers[3] ? (1 << 3) : 0 )
| ( integers[4] ? (1 << 4) : 0 )
| ( integers[5] ? (1 << 5) : 0 )
| ( integers[6] ? (1 << 6) : 0 )
| ( integers[7] ? (1 << 7) : 0 );
Actually this works if the integers have the value 0 or non-0.
If you are certain that they can only be 1 or 0, the following
may be faster:
Ceci marche si les integers ont les valeurs 0 ou non-0. Si vous
etez certain que ils n'ont que 1 ou 0, le ci-dessus peut-etre
plus vite:
character= (integers[0] << 0)
| ( integers[1] << 1)
| ( integers[2] << 2)
| ( integers[3] << 3)
| ( integers[4] << 4)
| ( integers[5] << 5)
| ( integers[6] << 6)
| ( integers[7] << 7);
What gives you the idea that Anna speaks French?
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
CBFalconer wrote:
What gives you the idea that Anna speaks French?
Her email address petitmuoton?
CBFalconer wrote:
viza wrote:
>Anna wrote:
>>Ben Bacarisse <ben.use...@bsb.me.ukwrote: Anna <petitmou...@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of type char(1 octet) with no hope . Could anyone propose a simple way to do it? Thank you very much. It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing. thank you Ben. I have bit sequence 01010101.... that I want to implement into a simulator, but in the simulator, they use a char as a type of data since each int comprise between 2-4 octet and one char is only 1 octet (=8 bits 0 or 1). I guess it will make the simulator run faster, I'm not sure.
Do you mean that you have eight integers but that each one has either the value 1 or 0? In that case, do:
Est-ce que vous-voulez dire que vous avez huite integers et que chaqun d'entre eux a le valeur 1 ou 0? En ce cas, faitez:
int integers[8]; unsigned char character;
character= ( integers[0] ? (1 << 0) : 0 ) | ( integers[1] ? (1 << 1) : 0 ) | ( integers[2] ? (1 << 2) : 0 ) | ( integers[3] ? (1 << 3) : 0 ) | ( integers[4] ? (1 << 4) : 0 ) | ( integers[5] ? (1 << 5) : 0 ) | ( integers[6] ? (1 << 6) : 0 ) | ( integers[7] ? (1 << 7) : 0 );
Actually this works if the integers have the value 0 or non-0. If you are certain that they can only be 1 or 0, the following may be faster:
Ceci marche si les integers ont les valeurs 0 ou non-0. Si vous etez certain que ils n'ont que 1 ou 0, le ci-dessus peut-etre plus vite:
character= (integers[0] << 0) | ( integers[1] << 1) | ( integers[2] << 2) | ( integers[3] << 3) | ( integers[4] << 4) | ( integers[5] << 5) | ( integers[6] << 6) | ( integers[7] << 7);
What gives you the idea that Anna speaks French?
Calling herself 'petitmouton' is a clue.
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
"viza" <to******@gmil.comwrote in message
On Sun, 15 Jun 2008 03:00:50 -0700, Anna wrote:
Est-ce que vous-voulez dire que vous avez huite integers et que chaqun
d'entre eux a le valeur 1 ou 0? En ce cas, faitez:
Crosspost French to comp.lang.c.fr
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
"Anna" <pe*********@gmail.comwrote in message
thank you Ben. I have bit sequence 01010101.... that I want to
implement into a simulator, but in the simulator, they use a char as a
type of data since each int comprise between 2-4 octet and one char is
only 1 octet (=8 bits 0 or 1). I guess it will make the simulator run
faster, I'm not sure.
char inputchar = 0x55; will set the variable inputchar to 01010101
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
On 15 Jun 2008 at 15:27, Malcolm McLean wrote:
"viza" <to******@gmil.comwrote in message
>Est-ce que vous-voulez dire que vous avez huite integers et que chaqun d'entre eux a le valeur 1 ou 0? En ce cas, faitez:
Crosspost French to comp.lang.c.fr
Describing that as French is more than a little generous...
On 15 juin, 13:33, viza <tom.v...@gmil.comwrote:
Hi
On Sun, 15 Jun 2008 03:00:50 -0700, Anna wrote:
On 15 juin, 11:52, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
Anna <petitmou...@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of
type char(1 octet) with no hope . Could anyone propose a simple way
to do it? Thank you very much.
It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing.
thank you Ben. I have bit sequence 01010101.... that I want to implement
into a simulator, but in the simulator, they use a char as a type of
data since each int comprise between 2-4 octet and one char is only 1
octet (=8 bits 0 or 1). I guess it will make the simulator run faster,
I'm not sure.
Do you mean that you have eight integers but that each one has either the
value 1 or 0? In that case, do:
Est-ce que vous-voulez dire que vous avez huite integers et que chaqun
d'entre eux a le valeur 1 ou 0? En ce cas, faitez:
int integers[8];
unsigned char character;
character= ( integers[0] ? (1 << 0) : 0 )
| ( integers[1] ? (1 << 1) : 0 )
| ( integers[2] ? (1 << 2) : 0 )
| ( integers[3] ? (1 << 3) : 0 )
| ( integers[4] ? (1 << 4) : 0 )
| ( integers[5] ? (1 << 5) : 0 )
| ( integers[6] ? (1 << 6) : 0 )
| ( integers[7] ? (1 << 7) : 0 );
Actually this works if the integers have the value 0 or non-0. If you
are certain that they can only be 1 or 0, the following may be faster:
Ceci marche si les integers ont les valeurs 0 ou non-0. Si vous etez
certain que ils n'ont que 1 ou 0, le ci-dessus peut-etre plus vite:
character= (integers[0] << 0)
| ( integers[1] << 1)
| ( integers[2] << 2)
| ( integers[3] << 3)
| ( integers[4] << 4)
| ( integers[5] << 5)
| ( integers[6] << 6)
| ( integers[7] << 7);
HTH
viza
Bonjour Viza,
Bien joué, je parle français aussi :-) merce beaucoup pour ta réponse.
Je trouve très intéressant et je pense que je vais essayer
d'implementer ce ci sur mon programme. Merci, merci, merci
Anna
On 15 juin, 13:33, viza <tom.v...@gmil.comwrote:
Hi
On Sun, 15 Jun 2008 03:00:50 -0700, Anna wrote:
On 15 juin, 11:52, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
Anna <petitmou...@gmail.comwrites:
I try to put 8 int bit for example 10100010 into one character of
type char(1 octet) with no hope . Could anyone propose a simple way
to do it? Thank you very much.
It would help is we saw what you did. I would write:
unsigned char c = 0xA2; /* Hex A2 is 1010 0010 */
Not that unsigned char is almost always safer for this sort of thing.
thank you Ben. I have bit sequence 01010101.... that I want to implement
into a simulator, but in the simulator, they use a char as a type of
data since each int comprise between 2-4 octet and one char is only 1
octet (=8 bits 0 or 1). I guess it will make the simulator run faster,
I'm not sure.
Do you mean that you have eight integers but that each one has either the
value 1 or 0? In that case, do:
Est-ce que vous-voulez dire que vous avez huite integers et que chaqun
d'entre eux a le valeur 1 ou 0? En ce cas, faitez:
int integers[8];
unsigned char character;
character= ( integers[0] ? (1 << 0) : 0 )
| ( integers[1] ? (1 << 1) : 0 )
| ( integers[2] ? (1 << 2) : 0 )
| ( integers[3] ? (1 << 3) : 0 )
| ( integers[4] ? (1 << 4) : 0 )
| ( integers[5] ? (1 << 5) : 0 )
| ( integers[6] ? (1 << 6) : 0 )
| ( integers[7] ? (1 << 7) : 0 );
Actually this works if the integers have the value 0 or non-0. If you
are certain that they can only be 1 or 0, the following may be faster:
Ceci marche si les integers ont les valeurs 0 ou non-0. Si vous etez
certain que ils n'ont que 1 ou 0, le ci-dessus peut-etre plus vite:
character= (integers[0] << 0)
| ( integers[1] << 1)
| ( integers[2] << 2)
| ( integers[3] << 3)
| ( integers[4] << 4)
| ( integers[5] << 5)
| ( integers[6] << 6)
| ( integers[7] << 7);
HTH
viza
Bonjour Viza,
Oui, je parle français aussi :-) merci beaucoup pour ton aide. Ton
programme me semble très intéressant, je vais essayer d'implementer ce
ci sur le simulateur. Merci beaucoup.
Anna This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jacob navia |
last post by:
Hi
Suppose you have somewhere
#define BOOL int
and somewhere else
typedef BOOL int;
|
by: Omats.Z |
last post by:
what is meaning os "char **option meet"?
I get a function like this:
__________________________________
int getchoice(char *greet, char *choices)
{
int chosen = 0;
int selected;
char **option;...
|
by: arnuld |
last post by:
what is the difference between these 2:
char name = "hackers";
char* name = "hackers";
|
by: liujiaping |
last post by:
I'm confused about the program below:
int
main(int argc, char* argv)
{
char str1 = "abc";
char str2 = "abc";
const char str3 = "abc";
const char str4 = "abc";
const char* str5 = "abc";
|
by: Anna |
last post by:
I try to put 8 int bit for example 10100010 into one character of type
char(1 octet) with no hope . Could anyone propose a simple way to do
it? Thank you very much.
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |