COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### convert long long integer to string using sprintf

• Email
• Follow

what is format for sprintf to convert long long integer (64 bits) to
string?


 0
Reply wenmang (87) 6/13/2006 10:11:54 PM

See related articles to this posting

wenmang@yahoo.com writes:

> what is format for sprintf to convert long long integer (64 bits) to
> string?

The format for "long long" is %lld (or %llx etc.).  Keep in mind
though, that a long long is not necessarily 64 bits.  If you
specifically need 64 bits, use the types defined in stdint.h and the
format macros in inttypes.h.

--
M�ns Rullg�rd
mru@inprovide.com

 0

wenmang@yahoo.com wrote:
> what is format for sprintf to convert long long integer (64 bits) to
> string?
>
You could look it up? If int is %d and long is %ld could it be %lld ?
Just guessing. I haven't looked it up.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---

 0

M�ns Rullg�rd <mru@inprovide.com> writes:
> wenmang@yahoo.com writes:
>> what is format for sprintf to convert long long integer (64 bits) to
>> string?
>
> The format for "long long" is %lld (or %llx etc.).  Keep in mind
> though, that a long long is not necessarily 64 bits.  If you
> specifically need 64 bits, use the types defined in stdint.h and the
> format macros in inttypes.h.

And keep in mind that your runtime library's version of sprintf()
might not support "%lld".  Mismatches between a compiler and the
runtime library it uses (for example, where the compiler supports
"long long", but sprintf() doesn't) are not uncommon.

Some older versions of sprintf() *might* use "%Ld" rather than "%lld".

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.

 0

Joe Wright wrote:
> wenmang@yahoo.com wrote:
>> what is format for sprintf to convert long long integer (64 bits) to
>> string?
>>
> You could look it up? If int is %d and long is %ld could it be %lld ?
> Just guessing. I haven't looked it up.
>
Hmm, and since %f is used to printf() a double, I can use %f to scanf() a
double, right?

Looking it up (or, indeed, asking in an ng) nearly always beats trying the
obvious if the language wasn't specifically designed to accommodate that. C
definitely isn't.

S.

 0

Skarmander <invalid@dontmailme.com> writes:

> Joe Wright wrote:
>> wenmang@yahoo.com wrote:
>>> what is format for sprintf to convert long long integer (64 bits) to
>>> string?
>>>
>> You could look it up? If int is %d and long is %ld could it be %lld ?
>> Just guessing. I haven't looked it up.
>>
> Hmm, and since %f is used to printf() a double, I can use %f to
> scanf() a double, right?

Wrong.  With scanf %f denotes a float, and %lf denotes a double.  This
difference is because the arguments to printf are subject to type
promotion, so any float arguments are converted to double.  The
arguments to scanf are pointers, so there is a need to differentiate
between pointer to float and pointer to double.

--
M�ns Rullg�rd
mru@inprovide.com

 0

M�ns Rullg�rd wrote:
> Skarmander <invalid@dontmailme.com> writes:
>
>> Joe Wright wrote:
>>> wenmang@yahoo.com wrote:
>>>> what is format for sprintf to convert long long integer (64 bits) to
>>>> string?
>>>>
>>> You could look it up? If int is %d and long is %ld could it be %lld ?
>>> Just guessing. I haven't looked it up.
>>>
>> Hmm, and since %f is used to printf() a double, I can use %f to
>> scanf() a double, right?
>
> Wrong.  With scanf %f denotes a float, and %lf denotes a double.  This
> difference is because the arguments to printf are subject to type
> promotion, so any float arguments are converted to double.  The
> arguments to scanf are pointers, so there is a need to differentiate
> between pointer to float and pointer to double.
>
You're ruining my fun.

For those who were enlightened by the above, read the FAQ at
http://www.c-faq.com as well. It covers the above and much more.

S.

 0

M=E5ns Rullg=E5rd wrote:
> wenmang@yahoo.com writes:
>
> > what is format for sprintf to convert long long integer (64 bits) to
> > string?
>
> The format for "long long" is %lld (or %llx etc.).  Keep in mind
> though, that a long long is not necessarily 64 bits.

It is at least 64 bits to be precise.

The New C Standard by Derek M. Jones
<q>
The C compiler for the Unisys e-@ction Application Development
Solutions (formerly known as the Universal Compiling System, UCS)[1331]
has 9-bit character types- 18-bit short, 36-bit int and long, and
72-bit long long.
</q>


 0

7 Replies
524 Views

Similar Articles

12/11/2013 7:44:39 AM
[PageSpeed]

Similar Artilces:

Best way to convert sequence of bytes to long integer
I have a byte string (Python 2.x string), e.g.: s = "g%$f yg\n1\05" assert len(s) == 10 I wish to convert it to a long integer, treating it as base-256. Currently I'm using: def makelong(s): n = 0 for c in s: n *= 256 n += ord(c) return n which gives: >>> makelong(s) 487088900085839492165893L Is this the best way, or have I missed some standard library function? Thanks in advance, -- Steven Steven D'Aprano, 20.01.2010 08:36: > I have a byte string (Python 2.x string), e.g.: > > s = ... Converting a string to integer. Hello again. I have another question. I am using 6.5. I have an edit box on a GUI and I need to restrict this entry to an integer value. Is there a way to do this in the property editor? If so How? If Not how can I do this? Below is a sample of code that checks to make sure the edit box is a number but necessarily an integer. AtNu1 = str2double(get(hObject, 'String')); if isnan(AtNu1) set(hObject, 'String', 0); errordlg('Input must be a number','Error'); end On Mon, 28 Jun 2004 23:22:57 -0400, michael lisowski wrote: > Hello again. I have another q... converting double to long Hi, I have to do something like below: double d = 0.151177; I need to have the mantissa part 151177 to a long variable i.e. I need to write a function to do this conversion: long convert(double value); Please help as I am not able to precisely get this done using the C code. Regards Kalyan >I have to do something like below: > >double d = 0.151177; That value is not exactly representable in binary floating point. >I need to have the mantissa part 151177 to a long variable i.e. I need >to write a function to do this conversion: > >long conver... Executing Long Query Strings I am attempting to execute a *long* query string via a ADODB.Recordset.Open (queryStr) call. Most of the time, the query string will be less than 100 characters, but in some cases, it may be up to 2000 chracters. Right now the code looks like this: Private Sub Command3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim rslt As ADODB.Recordset, rslt2 As ADODB.Recordset Dim sqlstr As String, sqlstr2 As String Dim interestID As Long, interestName As String, IID As String, interestSection As String, interestEmail As String Set rslt = New ADODB.Rec... convert string with comma into an integer hi, i need to convert a string like this 4,674 into an interger, but couldn't figure out how to do this. without using of Regexp. any help will be appriciated. "kiwi" <kshoyer@gmail.com> wrote: > hi, > i need to convert a string like this 4,674 into an interger, but > couldn't figure out how to do this. > without using of Regexp. And the problem is? Doing it without a regexp? Why? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: h... split long string over two lines I usually have to compose long strings like my$result = "....." which can go over multiple lines. I know C++ uses \ to allow multi-line strings. How does Perl allow this? I know I can do this: my $result = "....." . "....." Any other way? Thanks. TechCrazy wrote: > I usually have to compose long strings like > > my$result = "....." > > which can go over multiple lines. I know C++ uses \ to allow multi-line > strings. How does Perl allow this? > > I know I can do this: > > my \$result = ".....&...

how to convert an integer to std_logic_vector using vhdl
Hello everyone, I am trying to divite a std_logic_vector by a std_logic_vector. So i converted both of them into integers and divided. But how do i convert back to std_logic_vector. 1) Is the integer type or the division" / " synthesizable in xilinx ISE. 2) if i use integer as my output port and when i download my code onto the fpga, does it convert back to the binary. If yes to how many bits. I appreciate if you could answer these questions thanks Ashwin ashwin wrote: > Hello everyone, > I am trying to divite a std_logic_vector by a std_logic_vector. > So i conv...

How Python Implements "long integer"?

trouble converting a string to numbers using stringstreams
I have a string which I need to convert to integers. I was thinking that stringstreams would be the best way to convert them, but I am having trouble. Here's a simple example: #include <sstream> int main() { // string format: !AATTCCFF // '!' just need to convert this to a char // AA, TT, CC, FF are 2-byte unsigned hex (00-FF) std::string strInput = "!01020304"; std::istringstream strStream( strInput ); unsigned short int A,T,C,F; char Exclamation; // I know this is not correct strStream >> Exclamation >> A >> T >> C >> F; return...

Line breaking long urls using hyperref?
Hello, I'm using pdfTeX via MacTeX 2008 and I'm having trouble due to a curiously long url that I'd like included as a hyperlink in a pdf document, using the hyperref package's \url command. While hyperref seems happy putting a line break in after a `/' character, the particular url in question has an extraordinarily long name for the Web page and hyperref just gives me an overfull hbox. A minimum example document showing the problem is as follows: \documentclass[a4paper]{article} \usepackage[pdftex]{graphicx} \usepackage{hyperref} \begin{document} \noindent\raggedrigh...

Promotion converts long int to int implicitly ?
Hello I have an overloaded function like this: BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, long); BOOL SetFieldValue(_RecordsetPtr, LPCTSTR, int); And then I call the function like this: SetFieldValue(pRecordset, _T("Order"), long(i)+1); and the debugger shows that the int overload of my fuction is called. Is long( i ) + 1 not of type long ? Why is the int overload selected ? Thank you Timothy Madden Romania ----------------------------------------- And I don't wanna miss a thing Timothy Madden wrote: > Hello > > I have an overloaded function like this: > ...

How long is a piece of string? How big's a unit?
I'm working on my monthly column for Software Test & Performance magazine, and I'd like your input. The topic, this time around, is unit testing. Care to share some of your hard-won knowledge with your peers? In particular, what I'm looking for are experiences and advice about _developing_ the unit tests. (Managing and running them is something else again.) How big is a unit? How granular do you get? Do you have a particular process or checklist that you follow: ensuring that your tests look at interface, UI, etc.? Do you make a particular effort to create unit tests for the b...

Can I use a javascript function that converts string into bytes?
Problem: I want to store data from a form into a cookie but the cookie size is limited to 5kb. Eventually if the saved data crosses the limit 5 it does not get saved anymore. Is there any possibility to reduce the size of the string so that I can save some more datas in a cookie? I am doing a project where the usual requirement is to fill data online (real time). In the event of no internet connection I still want to fill the data and save in a form of a cookie (I am currently not sure in what other format I should save the offline data). Once I am connected to the internet it should be possi...

PL1 CHAR limit is 32767, but I need more long string type
Hi All PL1 type CHAR's largest length is 32767, but I need define a string type which largest length is 4M bytes to store MQ messages. I tried use AREA type, but I also need use SUBSTR and INDEX and other functions to find/process sub strings from MQ messages, is there any solution for this problem? Thank you in advance! Is the MQ message of type XML? In this case I would recommend you define an array like this dcl 1 mqdata(125), 3 mqchar char(32000); an parse it with PLISAXA or PLISAXC and forget about INDEX and SUBSTR. Jessica Ricky WU schrieb: ...

Ip addresses: Converting from long form to dotted form in a shell script
How do you convert long form ip addresses retreived from a database into a dotted form ip address? Bye Johann jzz wrote: > How do you convert long form ip addresses retreived from a database > into a dotted form ip address? Hi Johann, what do you mean with "long form ip address" and what with "dotted form ip address" Which of them is of this form: "1.2.3.4" ??? is this your long form or your dotted? Regards ... Rainer "jzz" <yojo101@hotmail.com> writes: > How do you convert long form ip addresses retreived fro...

Error: unterminated string literal (post may be a bit long for some readers)
In my attempts to eliminate using an IFRAME, I've tried the trick of using a cross-domain php script to generate a Javascript function, then load the <DIV> by executing an onload for the function in the <body> tag. sample <script type="text/javascript" src="http://www.foo.com/Directory/JSGenerate.php?B=25></script> <body onload='JSGetDiv()'> JSGetDiv shown below It works as long as the length of the data is small, otherwise the browsers (IE and FF) throw an error, in Firefox it's: unterminated string literal Is their some limit...

FAQ 5.16 Why do I sometimes get an "Argument list too long" when I use <*>?
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.16: Why do I sometimes get an "Argument list too long" when I use <*>? The "<>" operator performs a globbing operation (see above). In Perl versions earlier than v5.6.0, the intern...

FAQ 5.15 Why do I sometimes get an "Argument list too long" when I use <*>? #2 554018
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.15: Why do I sometimes get an "Argument list too long" when I use <*>? The "<>" operator performs a globbing operation (see above). In Perl versions earlier than v5.6.0, the intern...

Portability Of unsigned long long
Hi All, Is unsigned long long standard or not? Of course, I mean for C++. Seems too good to be true for my current dilema. TIA, -Le Chaud Lapin- -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] Le Chaud Lapin wrote: > Hi All, > > Is unsigned long long standard or not? > > Of course, I mean for C++. > > Seems too good to be true for my current dilema. > Not in C++03. I believe it will be standard in C++0x. -- [ See http://www.gotw.ca/resources/clcm.htm for info ...

How long is too long for cgi script?
What is the ballpark limit for the size of a script before the perl interpreter takes more than a few seconds to load it? I have a cgi script that is not CPU or memory intensive but is around a few thousand lines of code and uses a few modules. It runs in less than a second. Customers keep requesting new features and I am hesitant to just blindly growing the code. What is the point where the code will take too long to load into the interpreter (>3 seconds)? Can I juse use modules wiley-niley or do I have to count the lines of code in them too? And what if the code does become too large ? ...