Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to do many binary calculations of the form:

10.1^(1/11) base 2
10.001^(1/11) base 2
10.0001^(1/11) base 2
10.00001^(1/11) base 2
10.000001^(1/11) base 2

where 1/11 base 2 = 1/3 base 10.

I don't want to use bin2dec and dec2bin for binary. I want to do calculations like in DEC, without worrying about the cumbersome functions. So how can I do the binary calculations in Octave?

share|improve this question
You should label your radices: (10.1 base 2)^(1/3 base 10) (if that's correct) so your question is more clear. – Dennis Williamson Oct 5 '09 at 23:49
up vote 2 down vote accepted

The long answer is, it's possible, but you'll have to a) program it yourself, or b) get someone to program it for you. This method of writing fractional base-2 just isn't used in computing.

Programming a function to convert this representation of fractional binary numbers into standard IEEE754 double-precision floating point binary isn't impossible, so if it's an absolute must-have, it is doable.

share|improve this answer
Yes, but Masi's fundamental problem here is trying to get octave to interpret "10.1" as the binary 2 + a bit, as opposed to the decimal 10.1. The 10.1 absolutely has to be encapsulated as a argument to some functiont, but that is exactly what masi is trying to avoid - those "cumbersome functions" - so now you're right back where you started, a function to convert the number from it's hybrid binary format to a format understandable by octave.. – DaveParillo Oct 9 '09 at 3:59
correct (see my comments under your answer). this answer is clarifying exactly what he must do to accomplish what he wants to accomplish it -- despite being exactly the way he doesn't want to accomplish it. – quack quixote Oct 9 '09 at 4:31

The short answer is you can't. If I read your example right and 10.1 is supposed to be a binary floating point number?, then bin2dec is not really appropriate unless your number are all strings. I'm unaware of the concept of 'floating point binary' in octave. I think you'll have to manage the mantissa & exponent manually yourself if you want to do that.

If you're set on all bit arithmetic, have you tried the bit manipulation functions? bitset, etc.?

share|improve this answer
now that sounds like a conversion problem: just need to find a way to auto-convert his string to some binary-float format that Octave will understand. – quack quixote Oct 8 '09 at 22:38
~quack: everything is now in Binary, conversion is not my problem. I want to change base in the environment, not needing to worry about conversion all the time. – Masi Oct 8 '09 at 22:57
Masi, computers don't read floating point numbers in that kind of binary. they use IEEE754 or other representations. – quack quixote Oct 8 '09 at 23:04
eg your "10.1 base 2" = 4.5 base 10 = 0x40900000 in IEEE754 single-precision floating point format. (or does it? did i get the conversion to base 10 right?) see – quack quixote Oct 8 '09 at 23:06
oik? regards. xxxxxxx – Xavierjazz Oct 9 '09 at 3:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .