473,461 Members | 1,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading Hexadecimal value of an ASCII character..

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 2804
sicarie
4,677 Expert Mod 4TB
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
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 Expert Mod 4TB
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
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 (003265694732986859437210874169) 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
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
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
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 ...
1
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
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...
6
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...
30
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
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...
5
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...
1
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
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...
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
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,...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.