473,699 Members | 2,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does C# support bit fields (bit packing) in structure?

2 New Member
I think bit fields are not possible in c# structure but it is possible in c++.
For Example:
Expand|Select|Wrap|Line Numbers
  1. typedef struct
  2. {
  3. UINT16 SrcPort:16;
  4. UINT16 DstPort:16;
  5. UINT32 SeqNum:32;
  6. UINT32 AckNum:16;
  7. UINT16 Reserved1:4;
  8. UINT16 HdrLength:4;
  9. }IP_HDR
How can we create a structure like this in c# with bit fields?

My question is how we can set bit fields in C# structure.Is there any ways to do it in C#?
Sep 20 '13 #1
1 4692
Aurangzeb
11 New Member
No, C# does not offer any language features to define or access data storage smaller than 1 byte. You will have to mask and shift to isolate bit subranges within the data.
Sep 20 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

40
4236
by: Matt | last post by:
Please skip to the last paragraph if you are in a hurry. Some of the integer variables in my application will need to hold values bigger than 2^32-1. Others won't need to be that big. Time and space efficiencies on run-of-the-mill (read: 32 bit) microcomputers are important. I want to use some layer of abstraction comparable to C99's stdint.h so that my variable declarations specify the number of bits.
3
5977
by: Lars Rune Nøstdal | last post by:
struct X { unsigned int a : 1; unsigned int b : 1; }; int main() { X* x = new X; x->a = 1; x->b = 1;
5
4127
by: Taylor Howell | last post by:
Hello all, I have a delima. I have 8 5bit numbers that I need to pack into one (or more) variables. They then must be written (exactly 40bits (5Bytes)) to a file and have the ability to be put back into memory and then get the 5bit numbers out again. As I am not by any means proficient in C++ (still learning) I don't know how to go about doing this correctly. The way I was planning to do it is as follows: 1. create a character array...
13
11485
by: - Kees van der Bent - | last post by:
/* With the following: */ typedef struct { unsigned char a : 1; unsigned char b : 1; } sss_t; sss_t sss; unsigned char ppp; main()
2
394
by: Hetal | last post by:
Hey all ... I have a question. I have a structure as below: typedef struct { UInt8 data1; UInt8 data2_4b : 4,
10
2122
by: nambissan.nisha | last post by:
I am facing this problem.... I have to define a structure at runtime as the user specifies... The user will tell the number of fields,the actual fields...(maybe basic or array types or multiple arrays,etc) I do not understand how to define the structure at run time.i.e.what fields it will contain.
2
1959
by: sygnosys | last post by:
Hi, Does C# support struct bit definitions. For example is there a way to declare somethink like this C/C++ Code: struct CELL { // Declare CELL bit field unsigned short character : 8; // 00000000 ???????? unsigned short foreground : 3; // 00000??? 00000000 unsigned short intensity : 1; // 0000?000 00000000 unsigned short background : 3; // 0???0000 00000000 unsigned short blink : 1; // ?0000000 00000000
0
1301
by: ma740988 | last post by:
I often peruse source that use memory mapped registers as a configuration and/or command and status interface between embedded software and FPGA logic. In doing so you're given a register name accompanied by descriptions and a location in memory for reading/ writing data. For ex:. Revision Register - Location 0x0000 spare
1
2630
by: Joao Oliveira | last post by:
Hi ppl A simple question! I'm afraid it can be a bit silly, but I'm not an experienced programmer How does a 32 bit windows OS, comes with a calculator where you can sum really big numbers, over the limit of 32 bit integer (2,147,483,647). The problem is I want to make a calculator in C#. I know a solution would be use Long Int, but what if I want to add numbers even bigger than Long Int? So consider a solution without using Long Int. Don't...
0
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7777
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.