473,387 Members | 1,891 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,387 software developers and data experts.

Manipulate char* to increment next offset value.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. typedef char TUCHAR8;
  5.  
  6. typedef   signed char  TINT8;    /* Must force decl to be signed   */
  7. typedef unsigned char  TUINT8;   /* Must force decl to be unsigned */
  8.  
  9. typedef          short TINT16;   /* Decl will be signed as per std */
  10. typedef unsigned short TUINT16;  /* Must force decl to be unsigned */
  11.  
  12. typedef          int   TINT32;   /* Decl will be signed as per std */
  13. typedef unsigned int   TUINT32;  /* Must force decl to be unsigned */
  14.  
  15.  
  16. void putBits(TUCHAR8 *des ,const TUINT32 offset, const TUINT32 length,const TINT32 value)
  17. {
  18.  
  19.     TUCHAR8 *pTempData;
  20.     for(loop = 0 ; loop < offset; loop++)
  21.     {
  22.         pTempData++;
  23.     }
  24.  
  25.     pTempData  = des[offset];
  26. //  pTempData[offset];
  27.     TUINT16 loop;
  28.  
  29. cout<<"\n The value of temp is "<<pTempData[offset]<<endl;
  30. }
  31.  
  32. int main()
  33. {
  34.     TUCHAR8 *des;
  35.     des = new TUCHAR8 [8];
  36.     des = "avinash";
  37.     TINT32 value1 = 0xaa , value2 = 0xff;
  38.     putBits(des , (TUINT32)2 ,0x8 , value1 );
  39. //  putBits(des ,0x0 , 0x8 , value1);
  40.     //cout <<"\n The value of des is "<<des <<endl;
  41.  
  42. //  putBits(des , 0x8 , 0x8 , value2);
  43. //  cout<<"\n The value of des is "<<des <<endl;
  44.     return 0;
  45. }

THe problem is whenever I increment a char pointer its incrementing by one byte..how do I move to the next offset value which is in bits..
Oct 24 '07 #1
1 3671
weaknessforcats
9,208 Expert Mod 8TB
Any time you inecrment a pointer the address it contains chnages by the soxe of the object pointed at. So the address inside your char pointer is increased byt eh sizeof(char) when you increment.

To move among the bits,use the bit shift operators << and >>.
Oct 24 '07 #2

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

Similar topics

4
by: Joseph Suprenant | last post by:
I have an array of unsigned chars and i would like them converted to an array of ints. What is the best way to do this? Using RedHat 7.3 on an Intel Pentium 4 machine. Having trouble here, hope...
4
by: jagmeena | last post by:
Hello, I am sure this problem has been addressed before, however, I could'nt get a suitable solution to my problem. Hence I am posting here. Thanks a lot for all your help. The code I have is ...
30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
22
by: mail.zhf | last post by:
if have two char use equality, out first. example: char str = "gbdfssdffss"; out is: f.
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
9
by: | last post by:
void show( char *s, ...) is a function seemd like prinf code -------------- #include <stdio.h> #include <stdarg.h> void show( char *s, ...) { va_list stage;
8
by: machikelxol | last post by:
I'm having a strange error when I try reading from a file. here is the code: buffstring values = 1, 2, 3, 4 and then it crashes afterwards on the 4th iteration. This works fine until the fourth...
17
by: mdh | last post by:
In trying to understand the issue, I wrote this; #include <stdio.h> void f_output(char arg1, int limit); int main () { f(); return 0; }
17
by: spasmous | last post by:
I need a way to search through a block of memory for a char array "DA" using a pointer to a short. Ideally I would like to write something like: short *data = ... some data...; int j = 0;...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.