How to select option for binary coded value?


 
Thread Tools Search this Thread
Top Forums Programming How to select option for binary coded value?
# 1  
Old 06-30-2013
How to select option for binary coded value?

Hello everybody,

I looking for advice.

I'm trying to decode a binary file. Some parameters are "Binary coded", that means that if a byte in hexadecimal is "0A", then in binary is 00001010. So, to decode this Byte I need to refer to the table below (depending the value in binary format, the description applies for parameter A or for parameter B).

For this Byte (00001010), match the 3rd option "PARAMENTER A active".

So, my question is: What do you experts suggest me to do?, insert 6 IF Statements depending the value of the Byte, or put the table in another file?

Any other option?

*There are several bytes, where their decoding is explained in tables like I show here.


Code:
PARAMENTER A				PARAMENTER B				
B7	B6	B5	B4	B3	B2	B1	B0 	Description 
X	X	X	X	0	0	0	0	PARAMENTER A not provided 
X	X	X	X	1	0	0	0	PARAMENTER A provided
X	X	X	X	1	0	1	0	PARAMENTER A active
0	0	0	0	X	X	X	X	PARAMENTER B not provided 
1	0	0	0	X	X	X	X	PARAMENTER B provided
1	0	1	0	X	X	X	X	PARAMENTER B active

Thanks in advance for your help.

Regards

Last edited by Don Cragun; 06-30-2013 at 07:08 PM.. Reason: Remove extra end COLOR tag marker.
# 2  
Old 06-30-2013
Why don't you start by telling us what system you're using, what language you're using, and showing us what you've tried so far?
# 3  
Old 06-30-2013
Hello Don,

Initially because is not to complex, I'm trying with Matlab code.

To hecode only from hex to dec the first bytes is easy, but when
the byte is "binary coded" and the descrioption is in a table like I show in previous post, is not a direct conversion, because is based in a table and
I'm don't know if it is better to do several IF's for this.

This is what I have so far.
Code:
fid = fopen('C:\Binary_file');
x0 = fread(fid, [1,1],'*char');% Byte 0, Numeral 1, (ISO coded=Hex)
x1 = fread(fid, [1,22],'*char');% Bytes 1-12, (ISO coded)
x2 = fread(fid, [1,1],'*char'); %Byte 23,(Binary coded B0-B3).
x3 = dec2hex(fread(fid, [8,1])); %Byte 24.

x0 = fread(fid, [1,1],'*char');% Byte 25, (ISO coded=Hex)
x1 = dec2hex(fread(fid, [1,10]));% Byte 26, (ISO coded)

x2=hexToBinaryVector(x1,8);

disp(x2);
fclose(fid);

Thanks for any advice
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

The square root code I coded on this site...

Hi all, (mainly Neo)... I keep noticing that the SQRT code I wrote recently for a POSIX shell keeps appearing, (the green colour sticks out like a sore thumb). So I decided to take a look on Google. Guess what? UNIX.COM comes first in Google's listing just from two words, see image... (2 Replies)
Discussion started by: wisecracker
2 Replies

2. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

3. Homework & Coursework Questions

Decimal to BCD (Binary Coded Decimal)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Design an algorithm that accepts an input a decimal number and converts it into BCD (Binary... (2 Replies)
Discussion started by: caramba
2 Replies

4. UNIX for Dummies Questions & Answers

Decimal to BCD (Binary Coded Decimal)

Anybody please help me... Design an algorithm that accepts an input a decimal number and converts it into BCD (Binary Coded Decimal) representation. Also, draw its Flow Chart. This is a unix qn... plz post algorithm for that :confused: (1 Reply)
Discussion started by: caramba
1 Replies

5. Shell Programming and Scripting

Simple Script looking for Hard Coded Variables

Hi Guys Looking for a little help with a script to grep all files looking for hard coded variables - ie its IP address... so we know which files to look at before an IP change... This is what I have - but it seems to loop and never end... Any better suggestions? #!/usr/bin/ksh #simple... (2 Replies)
Discussion started by: serm
2 Replies

6. Shell Programming and Scripting

Select SQL Queries Option

count.sh#!/bin/ksh SQL1=`sqlplus -s usr/pwd @count.sql $1 $2 $3` SQL2=`sqlplus -s usr/pwd @selectall.sql $1 $2 $3` LIST="Count Select_All" select i in $LIST do if then echo $SQL1 elif then echo $SQL2 fi done (2 Replies)
Discussion started by: killboy
2 Replies

7. Shell Programming and Scripting

How to have color coded Terminal display,(like linux)

Hi all, I would like to know how to have a color display in the terminal... In the sense that, In many linux terminals,we have color coded for each file type, green for executable ,blue for dirs and so on... I wanted to know how i can have the same arrangement in solaris(b-79a) I am not... (5 Replies)
Discussion started by: wrapster
5 Replies

8. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies
Login or Register to Ask a Question