问题描述
我有一个问题,我需要在C和C#之间进行通信,我需要将数据从C格式发送到C#并相应地在C#中打印图形。
i只能使用4侧面的位(前三角形)和(x,y)的4,4位。然后在C#中检索它们,然后相应地绘制一个三角形。问题是,仅使用4位我只能传输0-15个数字,但是,用户可以自由输入0到32767之间的数字。我将如何将存储在4位中的数字的限制从16增加到32768以及那么如何在c#中检索这些数据呢。即时通讯使用socket进行进程间通信。
我尝试过:
套接字已用于进程间通信和位字段用于初始分配变量为Short用于存储位
i have a problem in which i needs to communicate between C and C# and i need to send data from C in bit format to C# and print Graphics in C# accordingly.
i have to use only 4 bits for side(ex triangle) and 4,4 bits for (x,y).then retrieve them in C# and then accordingly draw a triangle. Problem is that, using 4 bits only i ll be able to transfer only 0-15 numbers but, the user is free to enter numbers from 0 to 32767. How will i increase the limit of numbers stored in 4 bits from 16 to 32768 and how to retrieve this data in c# then. i m using socket for inter-process communication.
What I have tried:
sockets have been used for inter-process communication and bit fields for initial assignment of variable to Short for storing bits
推荐答案
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 10
1011 11
1100 12
1101 13
1110 14
1111 15
要获得更大的价值,您需要更多的位数。
要存储介于0和32767之间的值,您需要至少15位。
这是一个数学定律,而不是计算法!
To get any larger value, you need more bits.
To store values between 0 and 32767 inclusive, you need a minimum of 15 bits.
This is a law of mathematics, not computing!
这篇关于我在使用C ++中的位字段时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!