Click here to Skip to main content
15,902,189 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Architectural problem Pin
Stuart Dootson6-Apr-09 7:38
professionalStuart Dootson6-Apr-09 7:38 
GeneralRe: Architectural problem Pin
0x3c07-Apr-09 1:54
0x3c07-Apr-09 1:54 
GeneralRe: Architectural problem Pin
Stuart Dootson7-Apr-09 2:02
professionalStuart Dootson7-Apr-09 2:02 
GeneralRe: Architectural problem Pin
0x3c07-Apr-09 5:49
0x3c07-Apr-09 5:49 
AnswerRe: Architectural problem Pin
Garth J Lancaster5-Apr-09 17:41
professionalGarth J Lancaster5-Apr-09 17:41 
QuestionHuffman coding Pin
krish_amrita5-Apr-09 6:15
krish_amrita5-Apr-09 6:15 
AnswerRe: Huffman coding Pin
Cedric Moonen5-Apr-09 7:20
Cedric Moonen5-Apr-09 7:20 
AnswerRe: Huffman coding Pin
Luc Pattyn5-Apr-09 8:25
sitebuilderLuc Pattyn5-Apr-09 8:25 
Hi,

that is not beginner's stuff.

I did it once, long ago; you need to come up with a way to represent bit strings of limited length.

Here is one way of doing it:
imagine a struct "BITPATTERN" containing:
- int value; // holding up to 32 bits (right-aligned)
- int signif; // holding how many bits of value are significant.

Now implement a CONCAT(BITPATTERN a, BITPATTERN b) function that appends b to a.

The easiest way is by implementing a for loop, iterating over all the bits of b by:
- left-shifting a.value
- incrementing a.signif
- testing one bit of b.value
- if that bit is non-zero incrementing a.value

In addition one has to deal with overflows, i.e. data is not allowed to get lost in a.value while
shifting; one approach is to test for a.signif==8 and store a.value somewhere (to a file), clear it, and reset a.signif inside the CONCAT loop.

Finally, when all concatenations are done, some data may be left in a.value; so some extra zero bits should be concatenated until a.signif becomes 8 and everything gets flushed out.

BTW: you could do similar things using strings containing "0" and "1"; that is slightly easier to code, but far worse as performance goes; and the highest-performance implementations would not have a loop over the significant bits in b, they would use table lookups.

PS: I would expect some implementations to be available on the internet (and a fraction of them to be correct); make Google your friend.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


AnswerRe: Huffman coding Pin
Stuart Dootson5-Apr-09 11:46
professionalStuart Dootson5-Apr-09 11:46 
QuestionHow to override TR1 "function class"' operator()(****)//many parameters ? Thanks! The code is as follows. Pin
yjred5-Apr-09 5:20
yjred5-Apr-09 5:20 
AnswerRe: How to override TR1 "function class"' operator()(****)//many parameters ? Thanks! The code is as follows. Pin
Stuart Dootson5-Apr-09 11:50
professionalStuart Dootson5-Apr-09 11:50 
QuestionCTabCtrl Usage. Pin
FISH7865-Apr-09 2:57
FISH7865-Apr-09 2:57 
QuestionRe: CTabCtrl Usage. Pin
yjred5-Apr-09 5:03
yjred5-Apr-09 5:03 
AnswerRe: CTabCtrl Usage. Pin
FISH7865-Apr-09 6:24
FISH7865-Apr-09 6:24 
QuestionCRichEditCtl on CMDIchildWnd Pin
prithaa4-Apr-09 21:30
prithaa4-Apr-09 21:30 
Answeranother question Pin
Mohammadj5-Apr-09 0:26
Mohammadj5-Apr-09 0:26 
GeneralRe: another question Pin
Iain Clarke, Warrior Programmer5-Apr-09 12:20
Iain Clarke, Warrior Programmer5-Apr-09 12:20 
GeneralRe: another question Pin
Mohammadj7-Apr-09 0:39
Mohammadj7-Apr-09 0:39 
GeneralRe: another question Pin
Iain Clarke, Warrior Programmer7-Apr-09 10:57
Iain Clarke, Warrior Programmer7-Apr-09 10:57 
GeneralRe: another question Pin
Mohammadj8-Apr-09 2:52
Mohammadj8-Apr-09 2:52 
Questioninverse mapping Pin
Member 33753344-Apr-09 17:35
Member 33753344-Apr-09 17:35 
AnswerRe: inverse mapping Pin
Iain Clarke, Warrior Programmer6-Apr-09 2:05
Iain Clarke, Warrior Programmer6-Apr-09 2:05 
AnswerRe: inverse mapping Pin
Alan Balkany7-Apr-09 4:27
Alan Balkany7-Apr-09 4:27 
QuestionWindows Example Programs Pin
BobInNJ4-Apr-09 12:08
BobInNJ4-Apr-09 12:08 
QuestionRe: Windows Example Programs Pin
David Crow4-Apr-09 17:05
David Crow4-Apr-09 17:05 

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.