Muốn gọi hàm hextodec thì xuất ra mảng số dec nhưng chỉ xuất ra được số cuối cùng

Code mình có viết lại như bên dưới, muốn gọi hàm hextodec thì xuất ra mảng số dec nhưng chỉ xuất ra được số cuối cùng

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApplication2
{
    class Program
    {
 
        public static void readHexNumbers(ref int[] a)
        {
            StreamReader reader = new StreamReader(@"hex_numbers.txt");
            string hexValues = reader.ReadLine();
            string[] hexValuesSplit = hexValues.Split(' ');
            Console.Write(hexValues + "\n");
            for (int i = 0; i < hexValuesSplit.Length; i++)
            {
                int value = 0;
                foreach (string hex in hexValuesSplit)
                {
                    value = Convert.ToInt32(hex, 16);

                    a[i] = value;
                    // Console.Write(a);
                }
                
            }
         
        }
        public static void XuatMang(int[]a)
        {
            
            for (int i = 0; i < a.Length; i++)
            {
                Console.Write($"{a[i]}{" "}");
            }
        }
        static void Main(string[] args)
        {
            int n = 14;
            int[] a = new int[n];
            Program p = new Program();
            readHexNumbers(ref a);
            XuatMang(a);
            Console.ReadLine();
        }
    }
}

Lỗi này không thể chấp nhận được.
Lỗi nó thông báo cái gì?

Bạn có chắc chuỗi đúng định dang số thập lục phân?

3 Likes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApplication2
{
    class Program
    {
 
        public static void readHexNumbers(ref int[] a)
        {
            StreamReader reader = new StreamReader(@"hex_numbers.txt");
            string hexValues = reader.ReadLine();
            string[] hexValuesSplit = hexValues.Split(' ');
            Console.Write(hexValues + "\n");
            for (int i = 0; i < hexValuesSplit.Length; i++)
            {
                int value = 0;
                foreach (string hex in hexValuesSplit)
                {
                    value = Convert.ToInt32(hex, 16);

                    a[i] = value;
                    // Console.Write(a);
                }
                
            }
         
        }
        public static void XuatMang(int[]a)
        {
            
            for (int i = 0; i < a.Length; i++)
            {
                Console.Write($"{a[i]}{" "}");
            }
        }
        static void Main(string[] args)
        {
            int n = 14;
            int[] a = new int[n];
            Program p = new Program();
            readHexNumbers(ref a);
            XuatMang(a);
            Console.ReadLine();
        }
    }
}


hextodec

A post was merged into #3

Vòng lặp lồng nhau, sai bét rồi nhé. Bài này chỉ 1 vòng lặp.
Các giá trị 177 nhận được là giá trị cuối B1 đấy. Nhờ cả vào 2 vòng lăp lồng nhau đấy!

3 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?