Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to Initialise byte array with decimal, octal and hexadecimal numbers in C++

1 Answer

0 votes
#include <iostream>

int main()
{
    unsigned char arr1[] = {10, 20, 30, 40, 90}; // decimal values
    unsigned char arr2[] = {010, 077, 023, 034, 053};   // octal values 
    unsigned char arr3[] = {0x10, 0xAA, 0x67, 0xAB, 0xFF}; // hexadecimal values      

    int size = sizeof(arr1) / sizeof(arr1[0]);
     
    for (int i = 0; i < size; i++)
        std::cout << (int)arr1[i] << " ";
     
    std::cout << "\n";
 
    for (int i=0; i < size; i++)
        std::cout << std::oct << (int)arr2[i] << " ";
     
    std::cout << "\n";
     
    for (int i = 0; i < size; i++)
        std::cout << std::uppercase << std::hex << (int)arr3[i] << " ";
}
   
   
   
     
/*
run:
     
10 20 30 40 90 
10 77 23 34 53 
10 AA 67 AB FF 
  
*/

 



answered Jan 18, 2024 by avibootz

Related questions

1 answer 168 views
1 answer 158 views
1 answer 110 views
110 views asked Aug 25, 2021 by avibootz
1 answer 113 views
113 views asked Aug 25, 2021 by avibootz
...