declare array with specific characters

General discussion on mikroC.
Post Reply
Author
Message
saharul
Posts: 489
Joined: 08 Jul 2010 08:11

declare array with specific characters

#1 Post by saharul » 09 Jan 2019 08:42

hi ,

how to write code to declare 6 arrays and each array can only has 4 characters of binary numbers .The binary numbers will be generated by random.

for example i need four arrays that consists:-

array1 has '0110'
array2 has '1000'
array3 has '0110'
array4 has '1000'

if i write

char array[6]

it prepares 6 arrays but each array can have more than 4 characters,

many thanks

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: declare array with specific characters

#2 Post by stefan.filipovic » 10 Jan 2019 12:40

Hi,

I made an example project and examples of these functions you are referring to.

Please find the project in the attachment.

Kind regards,
Attachments
Example.zip
(39.45 KiB) Downloaded 93 times
Stefan Filipović

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: declare array with specific characters

#3 Post by saharul » 11 Jan 2019 01:26

Thank you Stefan.
your code of conversion to binary numbers worked well.
But after doing cross over, and i read back the decimal value after conversion and display to GLCD, it displayed unknown character.

i tried this code

Code: Select all

.......................
int value;char txt;

....................
value=char1;
........................
Int To Str(value,txt);
Glcd_Write_Text(txt,77,7,2);


do i need to write special conversion from binary to decimal using "pow" for each binary bits.

Many thanks Stefan

:D :D :D

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: declare array with specific characters

#4 Post by stefan.filipovic » 11 Jan 2019 10:55

Hi,

I'm sorry but I'm afraid that I have not understood you correctly.

Could you please share the whole code which explains what you intended to do?

I understand that you want to display something on the GLCD, but I can't see exactly how you have been trying to do that.

Kind regards,
Stefan Filipović

saharul
Posts: 489
Joined: 08 Jul 2010 08:11

Re: declare array with specific characters

#5 Post by saharul » 18 Jan 2019 04:51

Thank you for your reply,

I meant after doing cross over/exhange bits , how do I finally display the final result in decimal not in binary?

Many thanks

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: declare array with specific characters

#6 Post by stefan.filipovic » 18 Jan 2019 12:04

Hi,

If you want to convert a string with bits to the string with a decimal value, just call the function StrBitsToUChar from the project which I attached before, and after that call the function BytoToStr from the Conversions library, as shown below.

Code: Select all

unsigned char num1;
char array[] = "01010101";
StrBitsToUChar(array, &num1);
ByteToStr(num1, array);
Kind regards,
Stefan Filipović

Post Reply

Return to “mikroC General”