Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
64 binary number to decimal?

Subject: 64 binary number to decimal?

From: Sudheer

Date: 24 Feb, 2003 04:21:57

Message: 1 of 6

Hi,


 I am trying to convert a 64 bit binary number to decimal, which i am
not able to do it with bin2dec as the max it can take is 53 bits. Is
there any simple way to do this?


 I need to add four 64bit binary number, modulo 2^64, for which i am
converting all the four 64 bit binary numbers to double, adding them,
then taking modulo 2^64 and converting back from decimal to binary. I
have implemented this for 32 bit binary but for 64 bit binary number
i get the above problem.


 Thank You,
Sudheer

Subject: 64 binary number to decimal?

From: =?ISO-8859-1?Q?Ren=E9?=

Date: 24 Feb, 2003 12:59:59

Message: 2 of 6

Sudheer wrote:
> Hi,
>
>
> I am trying to convert a 64 bit binary number to decimal, which i am
> not able to do it with bin2dec as the max it can take is 53 bits. Is
> there any simple way to do this?
>
>
> I need to add four 64bit binary number, modulo 2^64, for which i am
> converting all the four 64 bit binary numbers to double, adding them,
> then taking modulo 2^64 and converting back from decimal to binary. I
> have implemented this for 32 bit binary but for 64 bit binary number
> i get the above problem.
>
>
> Thank You,
> Sudheer

uint64 and int64 may be summed in matlab

you may also write your own sum in @int, see the matlab help

For instance split your 64 bit words in 8 bit words, perform addition
according to the rules (carry) and compose your 64 bit answer.

René

Subject: 64 binary number to decimal?

From: John D'Errico

Date: 24 Feb, 2003 06:56:24

Message: 3 of 6

In article <eeb9c79.-1@WebX.raydaftYaTP>,
 Sudheer <vemulasu@engr.orst.edu> wrote:


> I am trying to convert a 64 bit binary number to decimal, which i am
> not able to do it with bin2dec as the max it can take is 53 bits. Is
> there any simple way to do this?
>
>
> I need to add four 64bit binary number, modulo 2^64, for which i am
> converting all the four 64 bit binary numbers to double, adding them,
> then taking modulo 2^64 and converting back from decimal to binary. I
> have implemented this for 32 bit binary but for 64 bit binary number
> i get the above problem.

What is wrong with this?

% a 64 bit binary number, as a row vector, unit position last
bits=round(rand(1,64));

% base conversion
conv=2.^(63:-1:0)';

decimal_value = bits*conv;

Is your problem that matlab is not able to represent this
number exactly in decimal? Matlab uses double precision floats
exclusively. If you need more, the simple option is vpa from
the symbolic toolbox, unless you want to implement a variable
precision class of your own.

Easy enough would be to write a binary variable precision
class. That is, overload the functions plus.m, minus.m &
mod.m, so they work on objects composed of binary vectors.
Easier still is just to write a couple of simple functions:
say plus_bi.m and mod_bi.m, to operate on binary vectors of
arbitrary length, all in binary. Just do the adds (and
carries, etc.) yourself. Then you can work in any number
of bits you want.

HTH,
John D'Errico

Subject: 64 binary number to decimal?

From: Peter Boettcher

Date: 24 Feb, 2003 09:05:42

Message: 4 of 6

Sudheer <vemulasu@engr.orst.edu> writes:

> Hi,
>
>
> I am trying to convert a 64 bit binary number to decimal, which i am
> not able to do it with bin2dec as the max it can take is 53 bits. Is
> there any simple way to do this?
>
>
> I need to add four 64bit binary number, modulo 2^64, for which i am
> converting all the four 64 bit binary numbers to double, adding them,
> then taking modulo 2^64 and converting back from decimal to binary. I
> have implemented this for 32 bit binary but for 64 bit binary number
> i get the above problem.

How about implementing the 64 bit adds as a pair of 32 bit adds? Use
simple string ops to get the first/last 32 bits of each binary
number, and don't forget the carry.


--
Peter Boettcher <boettcher@ll.mit.edu>
MIT Lincoln Laboratory
MATLAB FAQ: http://www.mit.edu/~pwb/cssm/

Subject: 64 binary number to decimal?

From: Khagendra Gupta

Date: 24 Feb, 2003 10:19:44

Message: 5 of 6

You need the Extended Symbolic Math Toolbox to be able to convert binary
strings that are larger then 52 bits to decimal. If you have the Extended
Symbolic Math Toolbox, then you can use the following commands to obtain the
same:

maple('convert(11110001011111000101111100010111110001011111000101010,decimal
,binary)')

yields

8496527156231722

-Khagendra Gupta

kgupta@mathwork.com

"Sudheer" <vemulasu@engr.orst.edu> wrote in message
news:eeb9c79.-1@WebX.raydaftYaTP...
> Hi,
>
>
> I am trying to convert a 64 bit binary number to decimal, which i am
> not able to do it with bin2dec as the max it can take is 53 bits. Is
> there any simple way to do this?
>
>
> I need to add four 64bit binary number, modulo 2^64, for which i am
> converting all the four 64 bit binary numbers to double, adding them,
> then taking modulo 2^64 and converting back from decimal to binary. I
> have implemented this for 32 bit binary but for 64 bit binary number
> i get the above problem.
>
>
> Thank You,
> Sudheer

Subject: 64 binary number to decimal?

From: Sudheer

Date: 24 Feb, 2003 17:55:45

Message: 6 of 6

Hi,


 Thanks. I have the Extended Symbolic Math Toolbox and was able to
use these commands. I have another question regarding how to get the
64 bit character string in the matlab workspace into the maple.


For example,
>> h


h =


0110000101100010011000111000000000000000000000000000000000000000


>> class(h)


ans =


char
>>
maple('convert(1100001011000100110001110000000000000000000000000000000
00000000,decimal,binary)')


ans =


7017280570803617792


>> maple('convert(h,decimal,binary)')
??? Error using ==> maple
Error, (in convert/decimal) invalid input


ThankYou,
Sudheer


Khagendra Gupta wrote:
>
>
> You need the Extended Symbolic Math Toolbox to be able to convert
binary
> strings that are larger then 52 bits to decimal. If you have the
Extended
> Symbolic Math Toolbox, then you can use the following commands to
obtain
> the
> same:
>
>
maple('convert(11110001011111000101111100010111110001011111000101010,d
ecima
> l
> ,binary)')
>
> yields
>
> 8496527156231722
>
> -Khagendra Gupta
>
> kgupta@mathwork.com
>
> "Sudheer" <vemulasu@engr.orst.edu> wrote in message
> news:eeb9c79.-1@WebX.raydaftYaTP...
>> Hi,
>>
>>
>> I am trying to convert a 64 bit binary number to decimal,
which i am
>> not able to do it with bin2dec as the max it can take is 53
bits. Is
>> there any simple way to do this?
>>
>>
>> I need to add four 64bit binary number, modulo 2^64, for which
i am
>> converting all the four 64 bit binary numbers to double, adding
them,
>> then taking modulo 2^64 and converting back from decimal to
binary. I
>> have implemented this for 32 bit binary but for 64 bit binary
number
>> i get the above problem.
>>
>>
>> Thank You,
>> Sudheer
>
>
>

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us