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:
Binary adder/subtracted with over and unverflow.

Subject: Binary adder/subtracted with over and unverflow.

From: Deyan Levski

Date: 8 Oct, 2012 15:15:08

Message: 1 of 3

Hello everyone,

I am wondering if there is a quick way of adding or subtracting binary numbers in Matlab, and keeping the same bit vector length. To illustrate what I mean here is an example:

A = [0 0 0 0]
B = [0 0 0 1]

And I would like to subtract A-B and have the result in the following format:

C = A-B ----> therefore in this case - C = [1 1 1 0].

This is what most RTL languages (VHDL, Verilog) will interpret when performing A-B. The question here is if these is an existent built-in function or a quick way to achieve this?


Best Regards,
Deyan

Subject: Binary adder/subtracted with over and unverflow.

From: James Tursa

Date: 8 Oct, 2012 17:01:08

Message: 2 of 3

"Deyan Levski" <remove.this@gmail.com> wrote in message <k4uqls$scp$1@newscl01ah.mathworks.com>...
> Hello everyone,
>
> I am wondering if there is a quick way of adding or subtracting binary numbers in Matlab, and keeping the same bit vector length. To illustrate what I mean here is an example:
>
> A = [0 0 0 0]
> B = [0 0 0 1]
>
> And I would like to subtract A-B and have the result in the following format:
>
> C = A-B ----> therefore in this case - C = [1 1 1 0].
>
> This is what most RTL languages (VHDL, Verilog) will interpret when performing A-B. The question here is if these is an existent built-in function or a quick way to achieve this?

How is this subtraction defined? Element-wise equality? Doesn't look like 2's complement integer arithmetic since I would have expected a C = [1 1 1 1] answer for that (bit pattern for a -1 result). Since I don't see how the "subtraction" is defined I can't offer any advice on how to do it in MATLAB.

James Tursa

Subject: Binary adder/subtracted with over and unverflow.

From: Muthu Annamalai

Date: 8 Oct, 2012 18:53:07

Message: 3 of 3

Hello Deyan
You want to see help for bitand(), bitxor() functions.

Tags for 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