Click here to Skip to main content
16,011,374 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: HELP Pin
Carlos Antollini7-Mar-02 3:17
Carlos Antollini7-Mar-02 3:17 
GeneralVC++:CAsyncSocket and SDI Pin
crasher7-Mar-02 3:09
crasher7-Mar-02 3:09 
GeneralRe: VC++:CAsyncSocket and SDI Pin
RobJones7-Mar-02 4:11
RobJones7-Mar-02 4:11 
GeneralRe: VC++:CAsyncSocket and SDI Pin
fara7-Mar-02 13:59
fara7-Mar-02 13:59 
GeneralRe: VC++:CAsyncSocket and SDI Pin
lucy7-Mar-02 4:13
lucy7-Mar-02 4:13 
QuestionHow to deal with a Word document? Pin
big20027-Mar-02 3:05
big20027-Mar-02 3:05 
AnswerRe: How to deal with a Word document? Pin
Carlos Antollini7-Mar-02 3:22
Carlos Antollini7-Mar-02 3:22 
Generalpacking bytes to form an int (32bit) Pin
Merle Pittman7-Mar-02 2:36
Merle Pittman7-Mar-02 2:36 
My Task:
I am reading data coming in from an instrument over a serial port. The data is received as 2 char bytes (8 bits each) which I need to pack into the lower 16 bits of an int. The instrument sends high-byte low-byte.

What is the most efficient way to do this?

Some of my ideas are:
- assign the first char to the int and bit shift it 8 bits to the left( << 8) and then OR the result with the next 8 bits. This would fill the lower 16 bits but I am concerned about efficiency, which is my greatest problem.
[does an 8-bit shift left require 8 cpu cycles to do this shift?]

- I could also use a union with bitfields to but again I am not sure about efficiency compared to other methods.

- my last thought would be to use a void pointer to step through an array, but I am not completely sure how this would work.


Could anyone shed some light on this topic for me? I would appreciate any suggestions/comments.

Thanks,

- Merle
Confused | :confused:
GeneralRe: packing bytes to form an int (32bit) Pin
Jon Hulatt7-Mar-02 2:51
Jon Hulatt7-Mar-02 2:51 
GeneralRe: packing bytes to form an int (32bit) Pin
Tomasz Sowinski7-Mar-02 2:50
Tomasz Sowinski7-Mar-02 2:50 
Generaldrive list, drive type and drive name Pin
Guy Lecomte7-Mar-02 2:27
Guy Lecomte7-Mar-02 2:27 
GeneralRe: drive list, drive type and drive name Pin
Tomasz Sowinski7-Mar-02 2:28
Tomasz Sowinski7-Mar-02 2:28 
GeneralRe: drive list, drive type and drive name Pin
Atul Dharne7-Mar-02 2:48
Atul Dharne7-Mar-02 2:48 
GeneralParsing MS Word file Pin
7-Mar-02 2:21
suss7-Mar-02 2:21 
GeneralRe: Parsing MS Word file Pin
Michael P Butler7-Mar-02 2:39
Michael P Butler7-Mar-02 2:39 
GeneralRe: Parsing MS Word file Pin
Atul Dharne7-Mar-02 3:05
Atul Dharne7-Mar-02 3:05 
GeneralRe: Parsing MS Word file Pin
8-Mar-02 0:00
suss8-Mar-02 0:00 
GeneralRe: Parsing MS Word file Pin
Carlos Antollini7-Mar-02 3:28
Carlos Antollini7-Mar-02 3:28 
GeneralRe: Parsing MS Word file Pin
Mike Nordell7-Mar-02 8:42
Mike Nordell7-Mar-02 8:42 
GeneralParsing MS Word file Pin
7-Mar-02 2:17
suss7-Mar-02 2:17 
GeneralThread problem.. Pin
Neha7-Mar-02 2:08
Neha7-Mar-02 2:08 
GeneralRe: Thread problem.. Pin
Tomasz Sowinski7-Mar-02 2:14
Tomasz Sowinski7-Mar-02 2:14 
GeneralRe: Thread problem.. Pin
Tim Smith7-Mar-02 2:20
Tim Smith7-Mar-02 2:20 
GeneralRe: Thread problem.. Pin
Neha7-Mar-02 2:45
Neha7-Mar-02 2:45 
GeneralRe: Thread problem.. Pin
Tomasz Sowinski7-Mar-02 2:56
Tomasz Sowinski7-Mar-02 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.