473,385 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Accessing each byte of a char


Is there any method that allows me have access to the individual bytes that
compounds a char variable ?

Regards,


Nov 15 '05 #1
7 1383
http://msdn.microsoft.com/library/de...sreadtopic.asp
"Tim Conner" <ti*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...

Is there any method that allows me have access to the individual bytes that compounds a char variable ?

Regards,

Nov 15 '05 #2
http://msdn.microsoft.com/library/de...sreadtopic.asp
"Tim Conner" <ti*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...

Is there any method that allows me have access to the individual bytes that compounds a char variable ?

Regards,

Nov 15 '05 #3
Tim,
Is there any method that allows me have access to the individual bytes that
compounds a char variable ?


((byte)c) and ((byte)(c>>8))

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #4
Tim,
Is there any method that allows me have access to the individual bytes that
compounds a char variable ?


((byte)c) and ((byte)(c>>8))

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #5
Tim,
Have you tried the System.BitConverter.GetBytes method.

It returns a byte array given most built-in types.

Hope this helps
Jay

"Tim Conner" <ti*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...

Is there any method that allows me have access to the individual bytes that compounds a char variable ?

Regards,

Nov 15 '05 #6
Tim,
Have you tried the System.BitConverter.GetBytes method.

It returns a byte array given most built-in types.

Hope this helps
Jay

"Tim Conner" <ti*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...

Is there any method that allows me have access to the individual bytes that compounds a char variable ?

Regards,

Nov 15 '05 #7
characters in C# are unicode, which means they're 16 bits, rather than 8
bits.

You can access them with array syntax, or with foreach syntax. If you want
to pull out the numeric value, you can then cast to a short or ushort.
"Tim Conner" <ti*******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...

Is there any method that allows me have access to the individual bytes that compounds a char variable ?

Regards,

Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Claudio Grondi | last post by:
Background information: --------------------------------- in order to monitor mainboard sensory data as fan speeds, temperatures, applications like SpeedFan http://www.almico.com/speedfan.php or...
1
by: J. Campbell | last post by:
I have a feeling that I'm doing things all ass-backwards (again ;-), and would like some advice. What I want to do is: put some data to memory and then access that memory space as an array of...
27
by: Daniel Lidström | last post by:
Hello! I want to work with individual bytes of integers. I know that ints are 32-bit and will always be. Sometimes I want to work with the entire 32-bits, and other times I want to modify just...
10
by: Christian Christmann | last post by:
Hi, I'm wondering if my small example is not "dangerous": #define SIZE 10 char global; char* globalPtr = global; int main()
14
by: rsood | last post by:
Hi I'm developing a program, and naturally I want it to be as portable as possible. I need to be able to access specific numbers of bytes in it, but as far as I know, there is no keyword in the...
16
by: quantumred | last post by:
Can I use pointer arithmetic on the members of a structure in the following way? Should I be worried about structure padding? This works in my debugger but I wonder if I'm bending some rule here. ...
5
by: pt | last post by:
Hi, i am wonderng what is faster according to accessing speed to read these data structure from the disk in c/c++ including alignment handling if we access it on little endian system 32 bits...
5
by: Andy | last post by:
I'm having trouble accessing an unmanaged long from a managed class in VC++.NET When I do, the contents of the variable seem to be mangled. If I access the same variable byte-by-byte, I get the...
16
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.