- #include <iostream>
-
using namespace std;
-
-
void getBitsFromStream( const char *const pData , const int offset, const int length , int *const value)
-
{
-
int tempOffset = offset;
-
const char *pTempData = &pData[tempOffset/8];
-
bool bitValue=0 ;
-
char bitMaskValue[] = {128 ,0x40 ,0x20 , 0x10 , 0x8 , 0x4 , 0x2 , 0x1};
-
int tempValue;
-
int tempLength = length-1;
-
for ( int loop =0 ; loop <length ; loop++ )
-
{
-
bitValue = *pTempData & bitMaskValue[tempOffset % 8];
-
tempOffset++;
-
if ( tempOffset % 8 == 0 )
-
{
-
pTempData++;
-
}
-
tempValue = bitValue;
-
tempValue = tempValue << tempLength;
-
*value = *value + tempValue;
-
tempLength--;
-
}
-
-
}
-
void getBitsFromStream( const char *const pData , const int offset, const int length , bool *const value )
-
{
-
const char *pTempData = &pData[offset/8];
-
char bitMaskValue[] = {0x80 ,0x40 ,0x20 , 0x10 , 0x8 , 0x4 , 0x2 , 0x1};
-
*value = *pTempData & bitMaskValue[offset % 8];
-
}
-
-
void putBitsInStream(char * pData , const int offset , const int length , const int value )
-
{
-
char *pTempData = &pData[offset/8];
-
int tempOffset = 0;
-
int leftValue =0;
-
int middleValue =0;
-
int rightValue =0;
-
if( offset % 8 != 0 )
-
{
-
tempOffset = 8 - (offset %8) ;
-
leftValue = value >>(offset % 8);
-
*pTempData = *pTempData | leftValue;
-
pTempData++;
-
}
-
for ( int loop =0; loop <(length-tempOffset)/8 ; loop++)
-
{
-
middleValue = value<<tempOffset ;
-
*pTempData = *pTempData | middleValue;
-
pTempData++;
-
tempOffset += 8;
-
}
-
if( tempOffset != length )
-
{
-
rightValue = value<<tempOffset;
-
*pTempData = *pTempData | rightValue ;
-
//pTempData++;
-
}
-
}
-
-
nt main()
-
{
-
char *str= NULL;
-
str = new char[90]; // allocate 90 bits of memory
-
putBitsInStream( str , 0 , 8 , 100 );
-
putBitsInStream( str , 8 , 1 , 1 );
-
int value=0 ;
-
getBitsFromStream( str , 0 ,8 , &value);
-
cout<<"\n THe value is "<<value<<endl;
-
bool a;
-
getBitsFromStream( str , 8 ,1 ,&a );
-
cout<<"\n the value of a is "<<a<<endl;
-
return 0;
-
}
could any tell why the value of a ..I am not getting.. at 1,
what is the problem please help me out.. - void putBitsInStream(char * pData , const int offset , const int length , const int value )
This function puts the value ( 4th parameter ) in the character pointer pData , from the offset (second parameter))onwards of length ( 3rd parameter) ..
note the value of second and third parameter is in terms of bits.. - getBitsFromStream( const char *const pData , const int offset, const int length , int *const value)
this function gets the bits from the character pointer ( pData ) from the offset (second parameter) of length ( third parameter ) and store the result in the value ( fourth parameters.
Hope you understood my problem.. please help me ..
1 1104
So what is the error? Does this compile? You do know that you are missing an i on 'int main()' right? After fixing that, does this work? What is the output? What is the desired output?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: tshad |
last post by:
I am just trying to decide whether to split my code and uses code behind. I
did it with one of my pages and found it was quite a bit of trouble.
I know that most people (and books and articles)...
|
by: tshad |
last post by:
Many (if not most) have said that code-behind is best if working in teams -
which does seem logical.
How do you deal with the flow of the work?
I have someone who is good at designing, but...
|
by: George2 |
last post by:
Hello everyone,
From the definition of working set, it is a subset of virtual pages resident in physical memory -- from book Windows Internals. It means working set could not be larger than...
|
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: 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: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
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: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
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: 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...
| |