Hi.
Hers im subtracting two 16bit numbers by using two 8bit num array.In case if first byte of array is less than first byte of second array den i hav to take borrow form second byte of first array.This i could do ..wat my doubt s suppose if i take 4 elements in array and first byte of first array is less than first byte of second array den im gonna take borrow from second byte of first array,if that second byte of first array is 0 den how can i take borrow from third byte of first array..plz suggest me some ints
This is the pgm which i did for 2bytes is array -
#include<iostream.h>
-
#define N 2
-
-
typedef unsigned char byte;
-
-
class Megaint
-
{
-
private:
-
-
byte a[N];
-
unsigned int R[N];
-
public:
-
Megaint();
-
Megaint(byte m[]);
-
Megaint operator-(Megaint M);
-
void ShowMegaint();
-
};
-
-
int sub(byte n1,byte n2,byte n3)
-
{
-
int N1,N2,N3,N4;
-
N1=n1;N2=n2;N3=n3;
-
if((N1>10)&&(N1<100))
-
N2=N2*100;
-
else if(N1>100)
-
N2=N2*1000;
-
else
-
N2=N2*10;
-
-
N1=N2+N1;
-
N4=N1-N3;
-
return N4;
-
}
-
-
Megaint::Megaint()
-
{
-
int i;
-
for(i=0;i<N;i++)
-
{
-
a[i]=0;
-
R[i]=0;
-
}
-
}
-
-
-
Megaint::Megaint(byte m[])
-
{
-
int i;
-
for(i=0;i<N;i++)
-
{
-
a[i]=m[i];
-
-
}
-
}
-
-
-
Megaint Megaint::operator -(Megaint M)
-
{
-
Megaint res;
-
int i,R1,count=1;
-
for(i=0;i<N;i++)
-
{
-
if(a[i]>M.a[i])
-
res.R[i]=a[i]-M.a[i];
-
else
-
{
-
-
R1=sub(a[i],a[i+1],M.a[i]);
-
res.R[i]=R1;
-
res.R[i]=res.R[i]&0x0ff;
-
R1=R1>>8;
-
a[i+1]=R1;
-
-
-
}
-
}
-
return res;
-
}
-
-
-
void Megaint::ShowMegaint()
-
{
-
int i;
-
cout<<"the ans is "<<endl;
-
for(i=0;i<N;i++)
-
{
-
cout<<R[i]<<endl;
-
}
-
}
-
-
-
int main()
-
{
-
int i;
-
byte A[N]={0x91,0x05},B[N]={0x97,0x02};
-
/*cout<<"enter 1st array elements"<<endl;
-
for(i=0;i<N;i++)
-
{
-
cin>>A[i];
-
}
-
-
cout<<"enter 2nd elements"<<endl;
-
for(i=0;i<N;i++)
-
{
-
cin>>B[i];
-
}*/
-
-
Megaint first(A),second(B),third;
-
-
third=first-second;
-
third.ShowMegaint();
-
-
return 0;
-
}
thank u
3 3012 @susheela s
My dictionary translates 'den' to something absolutely not fitting this context like 'lair' and 'hideout'. Can you please clarify?
Also I don't understand the purpose of 'R' array in megaint - what data is it supposed to hold? Result of operation must be placed into 'a' anyway. Then, operator- takes and returns references to an object.
Besides that, you need function to take two bytes of operand, borrow from previous operation, and return result and borrow from this operation, like
subtr(unsigned char a, unsigned char b, unsigned char (or bool...) borrow, unsigned char& result, unsigned char& rborrow);
Then rborrow = b+borrow > a; // will they be cast to int before addition? afaik yes.
and result = a-b-borrow; // is it safe to assume that (unsigned char)(-1) == 0xff ? if not, proceed underflow separately...
Then call it for all N elements of the array.
Now i will be clear suppose if i have two bytes in array(05,06) and (07,03)
06 05
03 07
............
02 fe
in this case i took a borrow from second elelment of array1 to do first byte subtraction since 05 is less than 07..
If i want to extent this to any no bytes..how do i do my doubt is
09 00 05
05 02 08
.............
I this case 05 is less than 08 so e need to take a borrow from second byte but second byte in array is 00..therefore now i need to take borrow from third element 09..how do i do this..plz give any int.
donbock 2,426
Recognized Expert Top Contributor
I suggest you start by considering how you would implement a similar function that worked with an array of BCD values. A BCD (binary-coded decimal) value is a variable whose value is only allowed to range from 0 to 9. This should be a familiar problem -- its how you learned subtraction in elementary school. Once you're comfortable expressing that familiar rule as a software algorithm, it should be easy to generalize to an array of char's.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Rvenkatesh |
last post by:
How to use array string in C#.Net to compare and replace
characters between strings using function.
|
by: becte |
last post by:
I need to use three bytes to store four 6-bit integers (4 * 6 = 3 * 8)
like this
11111122|22223333|33444444
Suppose the input is, int c1, c2, c3, c4, range 0 .. 2^6 -1
and the output is int o1,o2,o3, range 0 .. 2^8-1
How to do this in a clever way?
(The 6 bits integers represent characters in range A-Z and 0-9)
|
by: nel |
last post by:
hi..
i want to know how to insert data using array in mysql where the data stored in field given? this field_name i taken from database....
thanks a lot...
|
by: palani12kumar |
last post by:
Hi
i've implemented a linear Queue using array.
But i've been struck up with a doubt!!!!!
Let me tell my problem with an example so that it can be clear.
Size of the Queue(array) is 5.
im initializing the front and rear to 0.
I continously add five elements to the Queue, so that now the rear points to the 4th position of the array and now the queue is full.
Now i delete all the five elements and now the Front and the Rear points at...
|
by: shoonya |
last post by:
i am using array as a data type in my db
....
(
sequence integer
) ;
and it stores a value
let {1,2,3,4,5}
| |
by: sriprasanna |
last post by:
Hello All,
In our project we have to store PDF, word document files in DataBase(SQL SERVER 2005). We have planned to convert the file to array of bytes and store the binary file into database. We are using c#, ASP.NET 2.0.
How to convert a PDF file and a Word Doc file to array of bytes? Is there any other means to implement this.
|
by: George2 |
last post by:
Hello everyone,
I am using Windows Server 2003 Performance Counter tool to monitor the memory consumed by my process.
The interested terms are working set, virtual bytes and private bytes. My questions are,
1. If I want to watch the real physical memory consumed by current process, which one should I monitor?
2. If I want to watch the physical memory + swap file consumed by current process, which one should I monitor?
3. Any more...
|
by: berrylthird |
last post by:
This question was inspired by scripting languages such as JavaScript. In JavaScript, I can access members of a class using array syntax as in the following example:
var myInstance:myClass = new myClass();
myInstance.member_0 = memberValue_0; // absolute notation
myInstance = memberValue_0; // relative notation
myInstance = memberValue_0; // nominal notation
You can initialize a struct in C/C++ like you would an array, as with the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |