473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

why the code is not working..

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void getBitsFromStream( const char *const pData , const int offset, const int length , int *const value)
  5. {
  6.      int tempOffset = offset;
  7.      const char *pTempData = &pData[tempOffset/8];
  8.      bool bitValue=0 ; 
  9.      char bitMaskValue[] = {128 ,0x40 ,0x20 , 0x10 , 0x8 , 0x4 , 0x2 , 0x1};
  10.      int  tempValue;
  11.      int tempLength = length-1;
  12.      for ( int loop =0 ; loop <length ; loop++ )
  13.      { 
  14.          bitValue = *pTempData & bitMaskValue[tempOffset % 8];
  15.          tempOffset++;
  16.          if ( tempOffset % 8 == 0 )
  17.          {
  18.             pTempData++;
  19.          }
  20.         tempValue = bitValue;
  21.         tempValue = tempValue << tempLength;
  22.         *value = *value + tempValue;
  23.         tempLength--;
  24.      }
  25.  
  26. }
  27. void getBitsFromStream( const char *const pData , const int offset, const int length , bool *const value )
  28. {
  29.     const char *pTempData = &pData[offset/8];
  30.     char bitMaskValue[] = {0x80 ,0x40 ,0x20 , 0x10 , 0x8 , 0x4 , 0x2 , 0x1};
  31.     *value = *pTempData & bitMaskValue[offset % 8];
  32. }        
  33.  
  34. void putBitsInStream(char * pData , const int offset , const int length , const int value )
  35. {
  36.     char *pTempData = &pData[offset/8];
  37.     int tempOffset = 0;
  38.     int leftValue =0;
  39.     int middleValue =0;
  40.     int rightValue =0;
  41.     if( offset % 8 != 0 )
  42.     {
  43.         tempOffset = 8 - (offset %8) ;
  44.         leftValue = value >>(offset % 8);
  45.         *pTempData = *pTempData | leftValue;
  46.         pTempData++;
  47.     }
  48.     for ( int loop =0; loop <(length-tempOffset)/8 ; loop++)
  49.     {
  50.         middleValue = value<<tempOffset ;
  51.         *pTempData = *pTempData | middleValue;
  52.         pTempData++;
  53.         tempOffset += 8;
  54.     }
  55.     if( tempOffset !=  length )
  56.     {
  57.         rightValue = value<<tempOffset;
  58.         *pTempData = *pTempData | rightValue ;
  59.         //pTempData++;
  60.     }
  61. }
  62.  
  63. nt main()
  64. {
  65.     char *str= NULL;
  66.     str = new char[90]; // allocate 90 bits of memory 
  67.     putBitsInStream( str , 0 , 8 , 100 );
  68.     putBitsInStream( str , 8 , 1 , 1 );
  69.     int value=0 ;
  70.     getBitsFromStream( str , 0 ,8 , &value);
  71.     cout<<"\n THe value is "<<value<<endl;
  72.     bool a;
  73.     getBitsFromStream( str , 8 ,1 ,&a );
  74.     cout<<"\n the value of a is  "<<a<<endl;
  75.     return 0;
  76. }
could any tell why the value of a ..I am not getting.. at 1,
what is the problem please help me out..
Expand|Select|Wrap|Line Numbers
  1. 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..
Expand|Select|Wrap|Line Numbers
  1. 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 ..
Nov 4 '07 #1
1 1104
sicarie
4,677 Expert Mod 4TB
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?
Nov 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

171
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)...
17
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
0
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...
1
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)...
1
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...
1
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....
0
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
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.