Win a copy of Design for the Mind this week in the Design forum!

# how to convert hex value to int array?

Sara Jonasn
Greenhorn
Posts: 9
HI all,

I want convert a hex number like 02468aceeca86420 to a two dimension int array ? how can i do it?

Junilu Lacar
Bartender
Posts: 7465
50
Please explain how a hexadecimal representation of a number is supposed to be mapped to a two-dimensional array. I can imagine doing it with a one-dimensional array but can't see how to do it for two dimensions. What goes in rows and what goes in columns?

Sara Jonasn
Greenhorn
Posts: 9
Junilu Lacar wrote:Please explain how a hexadecimal representation of a number is supposed to be mapped to a two-dimensional array. I can imagine doing it with a one-dimensional array but can't see how to do it for two dimensions. What goes in rows and what goes in columns?

yes you are right. how i can convert it to an one-dimensional int array?

fred rosenberger
lowercase baba
Bartender
Posts: 12098
30
The first step is always to describe what you need to do in English (or any other natural language of your choice). pretend you have to explain to a child what needs to be done. If you said "put a hexadecimal number into a 2-d array", do you think a child would have any clue what to do?

I'm 44, and I don't understand what you need done. So try explaining it in detail.

Usually, once you can do that, writing the code is easy.

Sara Jonasn
Greenhorn
Posts: 9
i have a hex string like "02468aceeca86420 "
i want convert it to an integer array . This array contain 0,1 .Any character in this string must convert to a binary number and it must store in array.For Example this hex string 02468aceeca86420 must convert to this :00000010......... that all these 0 and 1 must store in integer array (1-D not 2-D).

Campbell Ritchie
Sheriff
Posts: 48652
56
That is not very explicit. Do you mean you want to convert each hex digit into its corresponding 4 bits? And how do you intend to record those bits?

Henry Wong
author
Marshal
Posts: 21000
76
Campbell Ritchie wrote:That is not very explicit. Do you mean you want to convert each hex digit into its corresponding 4 bits? And how do you intend to record those bits?

Sounds like it will be an integer array, where each member can hold either a zero or a one. Not very effiecient storage in my opinion.

However, the sizing should be easy. Since each hex digit is exactly four bits, the size of the array is simply the length of the string times four.

Henry

Campbell Ritchie
Sheriff
Posts: 48652
56
You can actually use a boolean[] to reduce the storage.

I have just invented the BitSet, only backwards!