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.

32 bit left shift of a longint variable does not work

Status
Not open for further replies.

parafux

Newbie level 3
Joined
Jul 10, 2019
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
26
Hi all,

I have two integer variables scaling_0 and scaling_1
I want to attach them so that scaling_0 are the lower 32 bit and scaling_1 are the upper 32 bit. The result should be stored in a longint variable scaling.
I try this:

scaling = longint'(scaling_0) + (longint'(scaling_1) * longint'(2**32));

or also i tried this

scaling = longint'(scaling_0) + (longint'(scaling_1) * << 32);

for scaling_0 = -1 and scaling_1 = 15 i get this result:

scaling = 0xE_FFFFFFFF

I expect 0xF_FFFFFFFF

i also tried the cast with longint unsigned but get a compiler error.
 

Hi,

I'm not a programner, but I often need to read some code.
And here I'm always confused with the varable declarations.

When you say "integer" variable ... are you sure it is a signed_int_32 (are you sure it is not any other bit width ... and not unsigned)
When you say "longint" variable ... are you sure it is a signed_int_64 (are you sure it is not any other bit width ... and not unsigned)

If possible I recommend to declare the variables unambiguously.
Because the compiler need to treat the "cast" differently.

Klaus
 

The 0xEFF... result is correct for the calculations you are doing. Why do you expect any different result?

Try same thing with proper numbers...
-1 = FFFF FFFF FFFF FFFF (64 bits)
15 shifted right 32 bits is =
F 0000 0000
Add them up and you get..

1 0000 000E FFFF FFFF

Right?
Truncate the '1' which is 65th bit. You get
E FFFF FFFF

How many eff's are there in your result?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top