GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Apr-2008, 20:21
tootypegs tootypegs is offline
Junior Member
 
Join Date: Nov 2007
Posts: 32
tootypegs has a little shameless behaviour in the past

converting an unsigned char to an int?


hi i have s specific string of 8 bytes in my program which i have collected using the following code



CPP / C++ / C Code:


	unsigned char _1,_2,_3,_4,_5,_6,_7,_8;


infile.read (&_1,sizeof (_1)) ;		
infile.read (&_2,sizeof (_2)) ;
infile.read (&_3,sizeof (_3)) ;		
infile.read (&_4,sizeof (_4)) ;
infile.read (&_5,sizeof (_5)) ;		
infile.read (&_6,sizeof (_6)) ;
infile.read (&_7,sizeof (_7)) ;		
infile.read (&_8,sizeof (_8)) ;

char unixtime [9]; 

unixtime[0]=_1;
unixtime[1]=_2;
unixtime[2]=_3;
unixtime[3]=_4;
unixtime[4]=_5;
unixtime[5]=_6;
unixtime[6]=_7;
unixtime[7]=_8;
unixtime[8]='/0';



when i print out unixtime i get 45d732f6 which is ok but i want to store this value in an int called uTim. I also want to proceed my string with '0x' so that it is recognised as a string of hex. In an ideal world something like

CPP / C++ / C Code:
int uTim = 0x45d732f6;

is it possible to convert unixtime into and int?


thank you
Last edited by LuciWiz : 06-Apr-2008 at 12:09. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 04-Apr-2008, 05:16
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 116
L7Sqr has a spectacular aura about

Re: converting an unsigned char to an int?


If you are looking to convert a string to an int/long value, you can always use strtol. strtol will allow you to specify a base to use in the conversion so that you do not have to worry about prepending the 0x to your existing data.
 
 

Recent GIDBlogMore photos on Flickr by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linker Error athika_32 C Programming Language 6 03-Dec-2007 07:38
Could someone please look this over? clarjon1 C++ Forum 4 10-Jan-2007 07:05
Pointer initialization causing program abend? emanresu C Programming Language 0 12-Dec-2006 10:36
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 07:10
(read/write file) newbie need help plz momotx C Programming Language 6 28-Jan-2004 13:40

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:01.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.