Forum Discussion
High and low bits of 64-bit long and C#
Hi, what is the best way to take the high and low bits provided through iControl and create a 'long' in C from them?
I am currently using:
long wut = (ssl.statistics[0].value.high << 32) | ssl.statistics[0].value.low;
However, I am not sure this is how the values are intended to be used. Sometimes I am not getting the values I expect, but my expectations may be incorrect.
I can't help you with C, but maybe you'll be able to convert this. Here's how I do it in Python:
def convert_to_64_bit(high, low): """ Converts two 32 bit signed integers to a 64-bit unsigned integer. """ if high < 0: high = high + (1 << 32) if low < 0: low = low + (1 << 32) value = long((high << 32) | low) assert(value >= 0) return value
- Whoaa_aaa_14293NimbostratusAlthough I suppose I want a ulong, since the type specified by iControl is ulong.
- Whoaa_aaa_14293NimbostratusFor instance, using the values for STATISTIC_MEMORY_TOTAL_BYTES: ulong bl = (ulong)(val.high << 32) | (ulong)val.low; results in: High: 7 Low: -546316288 Result: 18446744073163235328 This is a crazy number and is in no way accurate. If I treat them as longs and not ulongs, the result is negative, which (again) is not accurate. Thoughts?
- mhite_60883Cirrocumulus
I can't help you with C, but maybe you'll be able to convert this. Here's how I do it in Python:
def convert_to_64_bit(high, low): """ Converts two 32 bit signed integers to a 64-bit unsigned integer. """ if high < 0: high = high + (1 << 32) if low < 0: low = low + (1 << 32) value = long((high << 32) | low) assert(value >= 0) return value
- Whoaa_aaa_14293NimbostratusI must be misunderstanding what the high and low values are then. Even when porting your code to C (which was basically just adding the if checks), I get the same exact behaviour. And I can't find any documentation detailing getting the real value out of these two high and low values.
- mhite_60883CirrocumulusHere is Joe's explanation: https://devcentral.f5.com/s/feed/0D51T00006i7P6lSAE https://devcentral.f5.com/s/articles/icontrol-apps-05-rate-based-statistics
- Whoaa_aaa_14293NimbostratusMarking this as an answer since it technically is.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com