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

Home Posts Topics Members FAQ

Reading Hexadecimal value of an ASCII character..

4 New Member
Morning everyone,

I'm still new to the programming world of C. I don't like asking for help but i think i may be asking for lots of help in the future months to come :(

Here's my problem..

I've been trying to write a command line program that will read a binary file, now say the following is an example of what i'm talking about:

00 00 FF 01 02 03 00 EF 34 67
00 01 FF 01 02 03 00 EF 34 67
00 02 FF 02 02 03 00 EF 34 67

The above Hex values all represent an individual character that have been formatted into lines of 10, in the binary file it's just one line of 30 characters.
what i'm trying to do is to count the occurances of a set of values into a counter and move on to read the next occurance.

so say i want to count how many times FF 01 appears in the file, however i only want it to count the ones that appear in the 3rd and 4th bit of every line. or:

00 00 FF 01 02 03 00 EF 34 67
00 01 FF 01 02 03 00 EF 34 67
00 02 FF 02 02 03 00 EF 34 67

how can i go about doing this? i've been racking my brain trying to come up with an answer but still no joy, Can anyone help me?
Sep 24 '07 #1
5 2825
sicarie
4,677 Recognized Expert Moderator Specialist
Two ways come to mind, but both need to ensure that the formatting of the file is standard. You can use a regex to parse for groups, or pull it apart yourself with strtok() .
Sep 24 '07 #2
Duncan McLeod
4 New Member
ok, i've had a look at those, and creating tokens sounds like the better idea, however i've had another idea.workaround ,

i could read the 4th and 5th bytes as a string using some form or character movement >> and compare that to a user input, then use an if statement to return true/false then move (??) spaces to the next occurance and repeat.

would this process work? could someone write a wuick line of code to express the movement of the pointer to the next value to check.

Regards
Sep 24 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
Well, that would depend on how it is stored in memory, but the theory is correct. You'd probably have to worry about what came before as well (and 'and' it with something after you move it that will wipe out the first part and keep the second). But that would be a pain, strtok() would be a lot easier, IMHO.
Sep 24 '07 #4
Duncan McLeod
4 New Member
after having a good read about strtok() i don't beleive that i can use that to get the desired effect of the program, as i'm not working with ASCII at all. i would need the delimiter value so that strtok can follow the delimitered pattern, and there might not always be one.

If i want the values in Bold to be counted to their own counter, e.g 08 00 is one value i want to use and 08 01 is another, there may not always be a 00 infront of them, and if i used that as the starting point wouldn't it get confused with all the other 00's there?

01 00 08 00 1F FE 00 00 00 00 00 00 00 00
03 00 08 00 1F FE 00 00 00 00 00 01 00 00
02 00 08 01 1F FE 00 00 00 00 00 02 00 00
00 00 08 01 1F FE 00 00 00 00 00 03 00 00

Taking a step back and looking at it logically could i use an array structure to cut the continuous data... e.g (00326569473298 685943721087416 9) into 3 arrays of 10 and then further divide each array into smaller arrays of 2+2+2+4 = 10 so that each of the smaller arrays A1-4 B1-4 C1-4 can be called into a true/false statement that can then be counted to a counter then printed on the screen?

The purpose of this is not to get the information to show up on the screen but to show how many times 08 00 apears in the file that is being read.

regards
Sep 24 '07 #5
Duncan McLeod
4 New Member
sorry i got a little too trigger happy with my keys, i meant to put in:

01 00 08 00 1F FE 00 00 00 00
03 00 08 00 1F FE 00 00 01 00
02 00 08 01 1F FE 00 00 02 00
00 00 08 01 1F FE 00 00 03 00

[ 01 00 ][ 08 00 ][ 1F FE 00 00 ][ 00 00 ]
[ 03 00 ][ 08 00 ][ 1F FE 00 00 ][ 01 00 ]
[ 02 00 ][ 08 01 ][ 1F FE 00 00 ][ 02 00 ]
[ 00 00 ][ 08 01 ][ 1F FE 00 00 ][ 03 00 ]
Sep 24 '07 #6

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

Similar topics

2
4035
by: Mike Jeffers | last post by:
Hi everyone, I need to convert data from a structure into hexadecimal ascii format. The structure is like this: struct ROOM_DATA { short room_number; short floor_number; long total_area;
2
8162
by: Pushpendra | last post by:
I am storing the encrypted password in xml file which I have saved in unicode format. While I try to read the xml file and create a dataset from it, it shows me the following error System.Xml.XmlException: The '{' character, hexadecimal value 0x7B, cannot begin with a name. The xml tag that I want to read is below: <DSNNAME>, ($»<{Š`Ê®A]]'Ï</DSNNAME> I will be very much thakful If someone writes about the solution for this...
1
10155
by: King Kong | last post by:
we are facing this kind of error when we double click the infragistic web grid please help me on this Regards Moid Iqbal Server Error in '/NetworkAccess' Application. ---------------------------------------------------------------------------- ----
9
6761
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger values, an example would be "AA" in EBCDIC hex wouldgive me the value of 63 in decimal (ASCII) when...
6
32002
by: jasn | last post by:
Hello I am getting the following error message when I try and send an XML sting to a web service, I read somewhere that most web services prefer ascii and some throw errors when using unicode so I have changed the encoding but still cant get rid of the error. System.Xml.XmlException: '', hexadecimal value 0x00, is an invalid character. Line 6, position 124. at System.Xml.XmlScanner.ScanHexEntity() at...
30
4572
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
8
18651
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in adv.
5
11651
by: Just D | last post by:
All, Any valuable idea about subj: "The '%' character, hexadecimal value 0x25" ? I tried to google, but nothing interesting was found. Is it IIS settings problem, user side problem or whatever? We receive it regularly and I guess the problem is not in our source codes. Please help! Just D.
1
1835
by: SanCaziano | last post by:
how can I get get the hexadecimal value of the char insert in a edit control (every time I press a key I want an alert message of its hexadecimal value)
14
2927
by: abhishekkarnik | last post by:
Hi, I am trying to read an exe file and print it out character by character in hexadecimal format. The file goes something like this in hexadecimal 0x4d 0x5a 0x90 0x00 0x03 .... so on When I read it into my array " two_bytes" which has 16 characters in total, I get each of these values read correctly, but when I attempt printing them out, it prints something like this: 0x4d 0x5a 0xffffff90 0x00 0x03 .... so on. I have no clue why. How...
0
8687
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8617
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
9174
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
9035
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
8914
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
8884
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
7751
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 projectplanning, coding, testing, and deploymentwithout 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...
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.