Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
bitmask
//gcc 7.4.0 #include <stdio.h> #include <stdbool.h> typedef struct { bool bit7:1; bool bit6:1; bool bit5:1; bool bit4:1; bool bit3:1; bool bit2:1; bool bit1:1; bool bit0:1; } bitmask; int main(void) { unsigned int voltage_word = 0; unsigned int voltage_word_shifted = 0; unsigned char high_byte = 0; unsigned char low_byte = 0; unsigned char reg13 = 0; unsigned char reg14 = 0; unsigned char new_high_byte = 0; unsigned char new_low_byte = 0; // calculate voltage word voltage_word = 0x02A5; printf("voltage_word: [0x%04X] \r\n", voltage_word); // shift left 1 bit voltage_word_shifted = (voltage_word << 1); printf("voltage_word_shifted: [0x%04X] \r\n", voltage_word_shifted); // break word into high byte and low byte high_byte = (voltage_word_shifted >> 8); low_byte = (voltage_word_shifted << 8) >> 8; printf("voltage high/low bytes: [0x%02X] [0x%02X]\r\n", high_byte, low_byte); // read current high byte & 0x07 to mask off correct bits then | calculated high byte reg13 = 0xA0; // current high byte new_high_byte = reg13 | high_byte; // read current low byte & 0x01 to mask off correct bits then | calulated low byte reg14 = 0x0D6; // current low byte new_low_byte = (reg14 & 0x01) | low_byte; printf("current value: [0x%02X] [0x%02X]\r\n", reg13, reg14); printf("new value: [0x%02X] [0x%02X]\r\n", new_high_byte, new_low_byte); return 0; }
run
|
edit
|
history
|
help
0
project menu
Spring 2017 Project 2 v1.5
If then price calculation v1
FahrenheitToCelcius
Project 3 part 2 Book v10.2
20171117_PITAGORAS
Assignment 8 pt 2
faster posting list using skip pointers
BSEARCH() WITH STRUCT
experimento con quicksort