mattate8
asked on
Function: strol
/*I can't seem to safely delete unused variables and strol doesn't seem to work?*/
/*am using Salford Plato V2.17*/
#include <iostream.h>
#include <clib.h>
class SegAdr
{
private:
unsigned short int Offset,Segment;
public:
SegAdr(unsigned short int a,unsigned short int b);
SegAdr(unsigned short int a);
virtual ~SegAdr();
unsigned short int GetSeg(void);
unsigned short int GetOff(void);
void OutputHex(unsigned short int);
unsigned short int Input(void);
};
SegAdr::SegAdr(unsigned short int a,unsigned short int b)
{
Segment = a;
Offset = b;
}
SegAdr::SegAdr(unsigned short int a)
{
Segment = a;
}
SegAdr::~SegAdr()
{
}
unsigned short int SegAdr::GetSeg(void)
{
return Segment;
}
unsigned short int SegAdr::GetOff(void)
{
return Offset;
}
//takes a 4 digit hex number and turns it into a 16 bit number
void SegAdr::OutputHex(unsigned short int a)
{
unsigned short int w,x,y,z;
char values[16]={'0','1','2','3 ','4','5', '6','7','8 ','9','A', 'B','C','D ','E','F'} ;
w = a & 0b0000000000001111;
x = a & 0b0000000011110000;
x=(x >> 4);
y = a & 0b0000111100000000;
y=(y >> 8);
z = a & 0b1111000000000000;
z=(z >> 12);
cout<<values[z]<<values[y] <<values[x ]<<values[ w];
}
//Takes 16 bit number and converts it to 4 digit hexi number
unsigned short int SegAdr::Input(void)
{
//doesn't seem to work if you delete w,x,y?
char w,x,y,z;
char v[4],*c[4];
unsigned short int a[4],b;
int i,count=0;
char values[22]={'0','1','2','3 ','4','5', '6','7',
'8','9','A','B','C','D','E ','F','a', 'b','c','d ','e','f'} ;
cout<<"Please input hex address: "<<endl;
while (count<=3)
{
z=getch();
for (i=0;i<=22;i++)
{
if (z==values[i])
{
putchar(z);
c[count]=&v[count];
v[count]=z;
a[count]=strtol(c[count],N ULL,16);
//strol seems to have some kind of weird cumulative error?
cout<<a[count]<<"a"<<endl;
count++;
}
}
}
b = a[0];
b=(b << 4);
b = b+a[1];
b=(b << 4);
b = b+a[2];
b=(b << 4);
b = b+a[3];
return b;
}
main ()
{
char d;
while (d!='q')
{
unsigned short int c,v;
/*cout<<"Please input number to convert into hex:";
cin>>c;*/
SegAdr n1(c);
v=n1.Input();
n1.OutputHex(v);
d=getch();
}
return 0;
};
/*am using Salford Plato V2.17*/
#include <iostream.h>
#include <clib.h>
class SegAdr
{
private:
unsigned short int Offset,Segment;
public:
SegAdr(unsigned short int a,unsigned short int b);
SegAdr(unsigned short int a);
virtual ~SegAdr();
unsigned short int GetSeg(void);
unsigned short int GetOff(void);
void OutputHex(unsigned short int);
unsigned short int Input(void);
};
SegAdr::SegAdr(unsigned short int a,unsigned short int b)
{
Segment = a;
Offset = b;
}
SegAdr::SegAdr(unsigned short int a)
{
Segment = a;
}
SegAdr::~SegAdr()
{
}
unsigned short int SegAdr::GetSeg(void)
{
return Segment;
}
unsigned short int SegAdr::GetOff(void)
{
return Offset;
}
//takes a 4 digit hex number and turns it into a 16 bit number
void SegAdr::OutputHex(unsigned
{
unsigned short int w,x,y,z;
char values[16]={'0','1','2','3
w = a & 0b0000000000001111;
x = a & 0b0000000011110000;
x=(x >> 4);
y = a & 0b0000111100000000;
y=(y >> 8);
z = a & 0b1111000000000000;
z=(z >> 12);
cout<<values[z]<<values[y]
}
//Takes 16 bit number and converts it to 4 digit hexi number
unsigned short int SegAdr::Input(void)
{
//doesn't seem to work if you delete w,x,y?
char w,x,y,z;
char v[4],*c[4];
unsigned short int a[4],b;
int i,count=0;
char values[22]={'0','1','2','3
'8','9','A','B','C','D','E
cout<<"Please input hex address: "<<endl;
while (count<=3)
{
z=getch();
for (i=0;i<=22;i++)
{
if (z==values[i])
{
putchar(z);
c[count]=&v[count];
v[count]=z;
a[count]=strtol(c[count],N
//strol seems to have some kind of weird cumulative error?
cout<<a[count]<<"a"<<endl;
count++;
}
}
}
b = a[0];
b=(b << 4);
b = b+a[1];
b=(b << 4);
b = b+a[2];
b=(b << 4);
b = b+a[3];
return b;
}
main ()
{
char d;
while (d!='q')
{
unsigned short int c,v;
/*cout<<"Please input number to convert into hex:";
cin>>c;*/
SegAdr n1(c);
v=n1.Input();
n1.OutputHex(v);
d=getch();
}
return 0;
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Disregard last comment.
You're error is more then likely related to the over run problem with the for loop, and I previously mension in my first comment.
You're also over writing variable v, c, and a.
These variables have a [4] length, but you're trying to write to the [23] position. (or 22 position in zero base)
These variables have a [4] length, but you're trying to write to the [23] position. (or 22 position in zero base)
This question didn't show any activity for more than 21 days. I will ask Community Support to close it unless you finalize it yourself within 7 days.
You can always request to keep this question open. But remember, experts can only help if you provide feedback to their comments.
Unless there is objection or further activity, I will suggest to accept
"Axter"
comment(s) as an answer.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
========
Werner
You can always request to keep this question open. But remember, experts can only help if you provide feedback to their comments.
Unless there is objection or further activity, I will suggest to accept
"Axter"
comment(s) as an answer.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
========
Werner
Force accepted
** Mindphaser - Community Support Moderator **
** Mindphaser - Community Support Moderator **
You need to pass a target variable.