Last active
April 20, 2024 00:58
-
-
Save Swyter/e6414c6c2451e4bbe3f5fad04bec7b75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
int fusb_measure_vbus_bsearch_comp(const void *a, const void *b) | |
{ | |
long unsigned int index = (long unsigned int) b; float volt = (index * 0.420f); | |
int val = volt <= 5.040000f ? 0x80 : 0; | |
printf("-- %u %u %f = %x\n", a, b, volt, val); | |
return val == 0x80 ? 1 : -1; | |
} | |
int main() | |
{ | |
printf("asdf\n"); | |
void* key = bsearch(NULL, NULL, 64, 1, fusb_measure_vbus_bsearch_comp); | |
printf("key: %p\n", key); | |
} |
Execution build compiler returned: 0
Program returned: 0
asdf
[-] 0 32 0
- 13.440000 = 0
[-] 0 16 0
- 6.720000 = 0
[-] 0 8 0
- 3.360000 = 80
- 3.780000 = 80
[-] 0 12 0
- 5.040000 = 80
- 5.460000 = 0
key: 12
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple method in Godbolt.
Alternate method in Godbolt. Checking that we're (
0x80
) and the index above us is (0x00
).