位字段操作三原色

编程入门 行业动态 更新时间:2024-10-11 17:27:12

位字段操作三<a href=https://www.elefans.com/category/jswz/34/1646585.html style=原色"/>

位字段操作三原色

位字段操作三原色

/** @Author: Your name* @Date:   2020-03-07 20:20:16* @Last Modified by:   Your name* @Last Modified time: 2020-03-07 21:23:59*/
#include <stdio.h>
#include<stdbool.h>
#define SOLID 0
#define DOTTED 1
#define DASHED 2
#define BLUE 4
#define GREEN 2
#define RED 1
#define BLACK 0
#define YELLOW (RED | GREEN)
#define MAGENTA (RED | BLUE)
#define CYAN (GREEN | BLUE)
#define WHITE (RED | GREEN | BLUE)
const char *color[8] = {"black","red","green","yellow","blue","magenta","cyan","white"};
struct box_props
{bool opaque : 1;unsigned int fill_color : 3;unsigned int : 4;bool show_border : 1;unsigned int border_color : 3;unsigned int border_style : 2;unsigned int : 2;
};
void showsettings(const struct box_props *pb);
int main()
{struct box_props box = {true,YELLOW,true,GREEN,DASHED};printf("Original box settings:\n");showsettings(&box);box.opaque = false;box.fill_color  = WHITE;box.border_color = MAGENTA;box.border_style = SOLID;printf("\nModified box settings:\n");showsettings(&box);getchar();return 0;
}
void showsettings(const struct box_props *pb)
{printf("Box is %s.\n",pb->opaque==true ? "opaque":"transparent");printf("The fill color is %s.\n",color[pb->fill_color]);printf("Border %s.\n",pb->show_border==true ? "shown":"not shown");printf("The border color is %s.\n",color[pb->show_border]);printf("The border style is ");switch(pb->border_style){case SOLID:printf("SOLID.\n");break;case DOTTED:printf("dotted.\n");break;case DASHED:printf("dashed.\n");break;default:break;}
}

运行结果入下:

Original box settings:
Box is opaque.
The fill color is yellow.
Border shown.
The border color is red.
The border style is dashed.Modified box settings:
Box is transparent.
The fill color is white.
Border shown.
The border color is red.
The border style is SOLID.

更多推荐

位字段操作三原色

本文发布于:2023-07-27 22:09:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1226450.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原色   字段   操作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!