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

Conversion to and from based real numbers

Hi

I didn't find this one from the FAQ:
I'm writing an input parser for numbers. Everything else is piece of
Cake, except how to parse real numbers that are in some other base
than 10, eg. 3A.B4 in base 12. This can be done for integers using
the strtoxx ISO C functions, but there is no base argument for the
float/double versions. How could I then print out reals in non-base 10
format?

THanks for answers.

--
Tapio
Nov 14 '05 #1
1 1348
Tapio Kelloniemi wrote:

I didn't find this one from the FAQ:
I'm writing an input parser for numbers. Everything else is piece
of Cake, except how to parse real numbers that are in some other
base than 10, eg. 3A.B4 in base 12. This can be done for
integers using the strtoxx ISO C functions, but there is no base
argument for the float/double versions. How could I then print
out reals in non-base 10 format?


For input, assuming you already know what the base is, parse the
integer portion with strtoul. That leaves a pointer to the
termination character, which you can check to be a '.'. Advance
the pointer. Check it points to a digit in the appropriate base.
Parse the remainder. The returned value represents itself divided
by base raised to the number of chars consumed. Combine
components.

Output of the integer portion is easy. The fractional portion can
be handled by successive multiplications by the base and
converting the integer portion of that into a digit.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ken | last post by:
I've been looking for a solution to a string to long conversion problem that I've run into >>> x = 'e10ea210' >>> print x e10ea210 >>> y=long(x) Traceback (most recent call last): File...
16
by: John | last post by:
Hi I am converting my access front-end/backend mdb app to adp. Are there any pitfalls I should be aware of? Thanks Regards
8
by: Perception | last post by:
Hello all, If I have a C-like data structure such that struct Data { int a; //16-bit value char; //3 ASCII characters int b; //32-bit value int c; //24-bit value }
4
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
4
by: rz0 | last post by:
Hi all, This is a question about both C89 and C99 and is based on my partial reading of the standard drafts (one from before C89 but mainly N1124). If appropriate, please give a...
9
by: jm.suresh | last post by:
Hi, I have a string '((1,2), (3,4))' and I want to convert this into a python tuple of numbers. But I do not want to use eval() because I do not want to execute any code in that string and limit...
24
by: Rajesh S R | last post by:
Isn't this code violation of C99 standard? #include <stdio.h> int main( void ) { float a = 0.7; if(a < 0.7) printf("Wrong"); else
7
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are...
32
by: Bob Greschke | last post by:
I'm reading 3-byte numbers from a file and they are signed (+8 to -8million). This seems to work, but I'm not sure it's right. # Convert the 3-characters into a number. Value1, Value2, Value3 =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.