Sponsored Content
Full Discussion: to convert int to hex
Top Forums Programming to convert int to hex Post 302152082 by WebKruncher on Tuesday 18th of December 2007 01:49:55 PM
Old 12-18-2007
Here's a C++ function

#include <string>
#include <sstream>
using namespace std;

//This spends some extra cycles, offers simplicity, elegance and safety.
string IntToHexString(int i)
{
stringstream ss;
ss<<"0x"<<hex<<i;
string retval; retval=ss.str().c_str();
return retval;
}


//usage
cout<<"Hex for 32 is "<<IntToHexString(32)<<endl;
// as always handle your seh exceptions with a try / catch.

Last edited by WebKruncher; 12-18-2007 at 02:51 PM.. Reason: typo.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to convert a string to int

Hi, i want to read a text file whose content(single line) will be a number like 1 or 2 or 3 ..... what i want to do is to read the file and increment the content of the file, using unix scripting. Regards, Senthil Kumar Siddhan. (2 Replies)
Discussion started by: senthilk615
2 Replies

2. Shell Programming and Scripting

How to Convert Hex value to Dec ?

Hi All, I want to convert below Hex value to Dec value in each column .How to do it ? This data is in a 1 file. 4e20 0475 2710 010f 7530 69a2 7530 7e2f 4e20 02dd 7530 6299 4e20 0c0a 7530 69a2 4e20 0a0b 2710 0048 7530 7955 4e20 0d23 7530 622d 7530 9121 2710 001f 7530 7d3f (6 Replies)
Discussion started by: Nayanajith
6 Replies

3. Programming

Convert HEX to EBCDIC IN C

i want to convert Hex value To EBCDIC value. i tried to convert hex to ascii and then to ebcdic but it doesn't give desired results . it doesn't give corresponding ebcdic value instead it gives some junk values. e.g; Hex EBCDIC ----------------- 81 a 82 b 83 c 84 d 85 e 86 f 87... (6 Replies)
Discussion started by: junaid.nehvi
6 Replies

4. Solaris

Convert DWORD to int on solaris for 64-bit

i am converting application from 32-bit to 64-bit on Solaris. How can I convert "DWORD" on Solaris 64-bit to int. Thanks. (1 Reply)
Discussion started by: amit_27
1 Replies

5. Shell Programming and Scripting

Convert hex to decimal or reverse is better?

Please Help Me! about the problem down under. I have 2 files with nearly the same characteristics, I have to convert one to the other format or the other format to one's format. I want to write it with awk. The first file contain lines like this: 300000001#A#Y#Y#Y#Y The other file contain... (4 Replies)
Discussion started by: Axel82
4 Replies

6. Programming

Handle int listen(int sockfd, int backlog) in TCP

Hi, from the manual listen(2): listen for connections on socket - Linux man page It has a parameter called backlog and it limits the maximum length of queue of pending list. If I set backlog to 128, is it means no more than 128 packets can be handled by server? If I have three... (3 Replies)
Discussion started by: sehang
3 Replies

7. Shell Programming and Scripting

Convert Hex - KSH

Hello, I woild like to convert hex on KSH not BASH: I tried to use: tmp=31 printf "\x"${tmp}"" it works on bash - Output is '1' but not on ksh. please advice on the right syntax. Thanks. (4 Replies)
Discussion started by: LiorAmitai
4 Replies

8. Shell Programming and Scripting

Convert to Hex in perl

Hi, i want to convert number 5860533159 to hexadecimal. i need to use perl. i used $foo = 5860533159; $hexval3 = sprintf("%#x", $foo); i am getting value as 0xffffffff. i need to get value as 0x15D50A3A7. when i converted using google calculator, i got the correct value, expected... (9 Replies)
Discussion started by: asak
9 Replies

9. Shell Programming and Scripting

Convert hex to decimal

can someone help me in converting hex streams to decimal values using perl script Hex value: $my_hex_stream="0c07ac14001676"; Every hex value in the above stream should be converted in to decimal and separated by comma. The output should be: 12,07,172,20,00,22,118 (2 Replies)
Discussion started by: Arun_Linux
2 Replies

10. Shell Programming and Scripting

Convert int to string in python

Hi, I have column 5 in a file which contains string like this for ex. RP11-125O5.2 SLCO1B1 CAPN1 FRMPD2 TXNL4B So I do by data = )] ValueError: invalid literal for int() with base 10: 'R' Can someday tell me how to convert this column into int successfully. Thank You in... (7 Replies)
Discussion started by: rossi
7 Replies
FBB::TempStream(3bobcat)					 Temporary fstream					  FBB::TempStream(3bobcat)

NAME
FBB::TempStream - Temporary fstream SYNOPSIS
#include <bobcat/tempstream> DESCRIPTION
FBB::TempStream objects are temporary std::fstreams opened with mode 0600 (user only read+write). The file created by a TempStream object is removed from the file system once the TempStream object goes out of scope. A TempStream object creates an empty file, and information can immediately be inserted into the TempStream object. To switch between inser- tion and extraction simply call seekg (for extraction) or seekp (for insertion). NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
std::fstream CONSTRUCTORS
o TempStream(std::string const &base = "/tmp/FBB::TempStream"): The constructor initializes the object and creates a file with the given base-name to which six random characters are appended. If the TempStream could not be constructed an FBB::Errno exception is thrown. The copy constructor is not available. MEMBER FUNCTIONS
All std::fstream members are available, as FBB::TempStream inherits from this class. In addition, TempStream itself offers o std::string const &fileName() const: The name of the created temporary file. EXAMPLE
#include <iostream> #include <bobcat/tempstream> using namespace std; using namespace FBB; int main() { TempStream ts("/tmp/demo"); ts << "Hello world "; ts.seekg(0); string line; getline(ts, line); cout << line << ", removed: " << ts.fileName() << ' '; } FILES
bobcat/tempstream - defines the class interface SEE ALSO
bobcat(7), mkostemp(3) BUGS
None reported. DISTRIBUTION FILES
o bobcat_3.01.00-x.dsc: detached signature; o bobcat_3.01.00-x.tar.gz: source archive; o bobcat_3.01.00-x_i386.changes: change log; o libbobcat1_3.01.00-x_*.deb: debian package holding the libraries; o libbobcat1-dev_3.01.00-x_*.deb: debian package holding the libraries, headers and manual pages; o http://sourceforge.net/projects/bobcat: public archive location; BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL). AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl). libbobcat1-dev_3.01.00-x.tar.gz 2005-2012 FBB::TempStream(3bobcat)
All times are GMT -4. The time now is 07:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy