Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program which will: 1. Read the name of a file containing 16-bit integers from the keyboard. 2. Open the file as a binary

Write a program which will:

1. Read the name of a file containing 16-bit integers from the keyboard.

2. Open the file as a binary file.

3. Read a 16-bit number from the file

4. Display the number on one line as:

a. A 16-bit binary number (16 bits must be printed -- i.e., include all the leading zeros)

b. A 4-digit hexadecimal number (all 4digits must be printed -- include leading zeros)

--this is what i have so far but i need to convert the hex vals to16 bit binary... Im Using C#--

namespace HW { class MainClass { public static void Main(string[] args) { Console.Write("Enter name of Binary file: "); String FileName = Console.ReadLine(); String file = "/Users/name/Desktop/"+FileName; var path = Directory.GetCurrentDirectory(); ReadFile(file); Console.ReadLine(); } static void ReadFile(String file){ using (BinaryReader br = new BinaryReader(File.Open(file, FileMode.Open))) { var position = 0; var length = (int)br.BaseStream.Length; while (position < length + 1) { var B = br.ReadByte(); string content = String.Format("{0:X2}", B); Console.Write(content + " "); position += sizeof(int); } Console.WriteLine(); } } }// end pf main class }

dat file looks like this:

80 00 20 1E 60 04 50 1B 80 00 20 1F 60 08 50 1B

Need and output like this:

1000000000000000 8000 16 0 0 0 0010000000011110 201E 4 0 0 30

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

Be able to cite the advantages of arbitration

Answered: 1 week ago