Skip to content

Instantly share code, notes, and snippets.

@takaswie
Created September 15, 2017 02:15
Show Gist options
  • Save takaswie/b391e26152048b974cfecca693ca6def to your computer and use it in GitHub Desktop.
Save takaswie/b391e26152048b974cfecca693ca6def to your computer and use it in GitHub Desktop.
calculation for absolute value.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(void)
{
uint8_t u;
int8_t s;
uint32_t i;
printf("step u s\n");
for (i = 0, u = 0, s = INT8_MIN; i <= 255; ++i, ++u, ++s) {
int8_t t = u;
int8_t m_u = 0x80;
int8_t m_s = 0x00;
printf("%02d: %d %d\n", i, abs(t ^ m_u), abs(s ^ m_s));
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment