Похожие чаты

How can I use uint8_t which represent 16 bit integers

as uint16_t pointer?
each two bytes in the uint8_t represent 16 bit integer
the first number here should be 1 but it outcome as 256

#include <stdint.h>
#include <stdio.h>

int main() {
uint8_t byteArray[] = {0x00, 0x01, 0x00, 0x02, 0x00, 0x03}; // Example data
uint16_t* uint16Array = (uint16_t*)byteArray;

for (int i = 0; i < 3; i++) {
printf("uint16Array[%d] = %u\n", i, uint16Array[i]);
}

return 0;
}

12 ответов

19 просмотров

Can use a union to scan through the elements

Though this should be just fine. Keep in mind that because of endianness you might get confused with the output

Jacob- Автор вопроса
Manav | avoid unnecessary messaging me
Though this should be just fine. Keep in mind that...

That's what I thought. Then If I want the first number to be 1 I should swap it like 0x01 0x00 instead of 0x00 0x01?

Jacob
That's what I thought. Then If I want the first n...

Ideally, it'll be better to stote numbers in u16 then scan it as u8

printf vs cout

Aditya Tiwari
printf vs cout

cout uses printf() internally

Aditya Tiwari
printf vs cout

They aren't talking about that. It's a topic a bit beyond you atm

Manav | avoid unnecessary messaging me
They aren't talking about that. It's a topic a bit...

Okay, but I only want to know , I use cout everywhere only , is it good?

Manav | avoid unnecessary messaging me
That's not true afaik

Hmm right, this answer also says that the implementation of cout isn't specified https://stackoverflow.com/questions/62852221/does-cout-cin-internally-call-printf-scanf-like-new-calls-malloc

Похожие вопросы

Обсуждают сегодня

А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
isn't utxo commitements pretty close though if someone wanted to get it over the finish line? my understanding is that most of the ground work was already down by verde
Luke High - Rabbi Of Bcash High Rabbi Of Bcash
23
@MrMiscipitlick А можешь макрос написать, который будет вычислять смещение относительно переданных меток? Просто .label1-.label2, и вернуть значение.
КТ315
35
is the buyback program live and at what prices are the purchases fixed? excuse me for the bland PA question, sophisticated defi people keke
Imnothere
20
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
Чем оно проблема?
Nikita Uzumaki
21
А еще в перле можно уже @arr1 + @arr2?
Sergei Zhmylove
53
@samkazemian - couple questions: Update on frxBTC? - This would do well with the current influx of institutional investment entering the space Update on future veFXS streams...
Costi
16
Hi, I was reading this https://twitter.com/HouseofChimera/status/1778078991762780408 about Verasity and their likely choice of Tron as blockchain for their token for its low f...
Jordi
13
Заметил в ghci 9.4.8: > :t (<*>) @((->)_) (<*>) @((->)_) :: (w -> (a -> b)) -> (w -> a) -> w -> b Разве не должно (w -> (a -> b)) быть записано как (w -> a -> b)? Это баг, ил...
Михаил
13
Карта сайта