Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me creat a 40 bit variable for PIC18LF8722

Status
Not open for further replies.

gravi

Full Member level 2
Joined
May 30, 2006
Messages
128
Helped
10
Reputation
20
Reaction score
10
Trophy points
1,298
Location
Hyderabad, India
Activity points
2,452
Hi
This is Ravi and working on PIC18LF8722 and mcc 18 compiler, can anyone help me creating 40 bit variable.

Thanking you
Ravi
 

Re: 40 bit Variable

That would be an array of 5 bytes.
Can you explain why you would need such a variable?
 

Re: 40 bit Variable

alexz said:
That would be an array of 5 bytes.
Can you explain why you would need such a variable?

I have been trying to capture an 24 bit register and add the existing value to the current value, since I have taken an long(32-bit) variable by type casting to the to do the above process it's getting over flowed, to prevent over flow I would like to take an 40 bit register.


Thanking you,
Ravi kumar

Added after 16 seconds:

alexz said:
That would be an array of 5 bytes.
Can you explain why you would need such a variable?

I have been trying to capture an 24 bit register and add the existing value to the current value, since I have taken an long(32-bit) variable by type casting to the to do the above process it's getting over flowed, to prevent over flow I would like to take an 40 bit register.


Thanking you,
Ravi kumar
 

Re: 40 bit Variable

Never heard of data types longer then 32 bits
 

Re: 40 bit Variable

Can't you use float variables, instaed of Long?
 

Re: 40 bit Variable

CMOS said:
Can't you use float variables, instaed of Long?


Float is 32 bits too
 

Re: 40 bit Variable

Floats are 32 as well as 64 bits. (Single and Double Precision)
Plus a 32 bit float can store larger value than a 32-bit long integer.
 

Re: 40 bit Variable

Float is 32 bits in PICs
 

Re: 40 bit Variable

alexz said:
Float is 32 bits in PICs
Well that actually depends on the compiler and not the controller.

However even if its 32-bit float, it will store value larger than what a 32-bit long integer can store.

The limits of 32-bit unsigned long is : 0 to 4294967295
where as that for 32-bit float is : ±1.175494E-38 to ±3.402823E+38

Using float even if 32-bit long addition overflows, the float result variable will be able to handle it.
 

Re: 40 bit Variable

Yes CMOS you are probably right
 

Re: 40 bit Variable

Hi CMOS,
Thankyou, but my compiler(MCC18) doesnot support Float variables.
 

Re: 40 bit Variable

gravi said:
Hi CMOS,
Thankyou, but my compiler(MCC18) doesnot support Float variables.


It does
 

Re: 40 bit Variable

I have assigned "4294967295" to a unsigned long variable and an unsigned float variable and printed using %lu and %lu as %f is not supported by my compiler float variable prints some other variable other than i assaigned.
 

Re: 40 bit Variable

You are limited in the exponent which can be whithin the range -126 to +128
 

Re: 40 bit Variable

gravi

i do not understand your problem

If you add 2 24 bit numbers it can never overflow a 32 bit value.

Example:

binary 111111111111111111111111 = hex FFFFFF
adding 111111111111111111111111 = hex FFFFFF gives hex 1FFFFFFE

But this only takes 25 bits of the 32 bit variable so there can not be an overflow.

Did I get this wrong?

best regards
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top