LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-01-2010, 03:51 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Bit packing


Language:
C++

Task:
Packing the required number of bits of all the given data, which can be of any valid C++ Datatype, in a given char*.

I have successfully completed packing of required number of bits of the following Datatypes:
1. Integer
2. Short
3. Character
4. Character array

Pending Datatypes:
1. Float
2. Structures, Enum, Union.

I don't have a clear idea how Structures and Floating points should be packed ?

I posted a question in Stackoverflow and the people there told me about bitset and Boost Serialization library.

While Googling further, I found BitMagic Library !
  • Can someone throw some light on the above two findings w.r.t Structures ?
  • (Little Endian machine) Which 5 digits from this number should be packed in a char*: 234.21234567 ?
  • Are there some standard algorithms for this type of bit packing ? I looked at Huffman Coding algorithm, but I am not sure whether it is meant for such kind of tasks !
I need guidance.

Last edited by Aquarius_Girl; 10-01-2010 at 07:53 AM. Reason: Added link
 
Old 10-01-2010, 09:49 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
When you say 'bit packing', do you mean that you are trying to reduce the size of the data? Or that you are trying to explicitly represent the data in a character array? (the term 'packing' in C/C++ usually means removing word alignment space from a structure)

Floating point numbers are typically represented using IEEE-754; there are several different sizes in common use. Both the digits and the exponent are represented; up to a third of the object is used for the exponent. The initial digits are the most significant.

Huffman coding is a way of encoding data so that more frequently occurring data is represented with less bits. One use is for lossless compression of data. However, the encoding has a variable bit length (which might not be what your question is).

If what you are interested in is the serialization of data (representation as a sequence of bytes), then the Boost serialization library is useful because it provides a platform independent way of converting a type into a character stream.

Converting a structure into a character stream is just a matter of converting each of its component types into a stream in turn.

Last edited by neonsignal; 10-01-2010 at 09:54 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bit packing Aquarius_Girl Programming 11 04-01-2010 01:33 AM
C++: Packing buffers for TCP carcassonne Programming 1 07-13-2006 02:41 AM
vcdimager + problem packing a video kurrupt Linux - Software 0 08-23-2005 12:54 PM
QMail packing a wobbly still AMMullan Linux - Software 2 06-11-2004 09:36 AM
Packing Customise data in Linux sachinnshah Linux - Laptop and Netbook 0 12-11-2003 07:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration