help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Right shifting in octave


From: Allen.Windhorn
Subject: RE: Right shifting in octave
Date: Fri, 2 May 2014 16:51:03 +0000

> -----Original Message-----
> From: address@hidden On
> Behalf Of goblinsly
> 
> I have to program crc in octave as a college asignment. The problem
> is that i am a total beginner as far as octave goes. That is why i
> am using the problem we were given in c as a guideline. It is
> proving to be useless though since, as you pointed, octave and c
> handle number differently.

Well, the purpose of the C program listing is probably to show you
WHAT you have to do.  Then it's up to you to figure out HOW to do in
Octave, which means you have to figure out how Octave likes to do
things.

C was made for fiddling with bits.  Octave was designed to hide the
bits from you to the greatest extent possible, so you don't have
to worry about them.  So there aren't any mechanisms for this in
Octave.  Octave loves matrices.  A string is a matrix, and so is an
array of integer ones and zeros, and you can shift these forms very
easily (do "help shift").  You can also do and, or, and not
operations on an array of Boolean values, which integer ones and
zeros are equivalent to.  I would approach the problem by trying to
reduce the checksum algorithm to basic Boolean operations.  Then
convert your checksum components from numbers to arrays of bits
and operate on those, then convert the result back to a number at
the end.  To convert to and from binary you may have to write a
loop (slow) dividing by 2 and checking the remainder, or adding
one or zero and doubling.  Other ideas, anyone?

> If i write number 0xFFFFFFFF in C ( unsigned int ), the result is -
> 1, if i write it in octave i get a very big number ( 4294967295).
> How would i force octave to get -1 ?

You'll get a lot farther working with Octave's strengths instead of
trying to force it to do something your way.

Regards,
Allen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]