Back

Topic

[KB1150]How to do bit shifting with long integers

Tags: Expression

3 years ago
By LM
Options
Print
Applies to:

PcVue 10.0 SP2 onwards


Summary:

This article explains how to extract bits from a word using an expression. Especially for very long words.


Details:

  1. We always recommend using this type of expression to extract a word bit:

(@Wordbit.Register01 & (2 POW 00)) >> 00
(@Wordbit.Register01 & (2 POW 01)) >> 01

Version 10.0 SP2

You can extract every bit, 0 to 31, from a 32-bit word or from a 64-bit word
You cannot extract bit 32 to 63 from a 64-bit word

Version 11.1 update 122 and later

You can extract every bit, 0 to 31, from a 32-bits word or from a 64-bits word
You cannot extract more than first 53 bits from a 64-bits word

 

  1. There is another type of expression that is simpler but not recommended for very long words 

@Wordbit.Register01>>00
@Wordbit.Register01>>01

Version 10.0 SP2

You can extract bit 0 to 30, from a 32-bits word or from a 64-bits word
You cannot extract bit 31 to 63 from a 64-bit word

 

Version 15.2.1 and later

You can extract every bit, 0 to 31, from a 32-bits word or from a 64-bits word
You cannot extract more than first 53 bits from a 64-bits word

 

Conclusion: you can never extract bit 53 to 63 from a 64-bits word

The screenshot below, coming from attached sample project launched with version 11.1 update 122, illustrates it.
On the right you see the maximum possible valid result playing with 53 bits (from 0 to 52):

Screenshot


Download sample project: WORDBIT.zip


Created on: 21 Feb 2022 Last update: 30 May 2024