473,748 Members | 2,615 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 4697
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
4251
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
5980
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
4129
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
11491
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
2130
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
1962
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
1306
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
2631
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
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
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
9333
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
8255
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...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3319
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
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.