unsigned

DataType for storing a long serial number (10 bytes)

限于喜欢 提交于 2019-12-11 18:34:21
问题 We have a device which has a 10 byte serial number which must be read into our application and stored into a .net datatype. In the device it is stored as an unsigned 10-byte (80-bit) number. I don't expect we will be performing any mathematical operations on this number, but only displaying it to the user. The .NET framework doesn't have a built in UNIT128 to store this datatype. My suggestion for storing this datatype is to create a 10 element byte array and read in the data into this array.

Why short* instead of char* for string? Difference between char* and unsigned char*?

喜你入骨 提交于 2019-12-11 15:38:40
问题 As the title says, I'm having two questions. Edit : To clarify, they don't actually use char and short , they ensure them to be 8-bit and 16-bit by specific typedefs. The actual type is then called UInt8 and UInt16 . 1. Question The iTunes SDK uses unsigned short* where a string is needed. What are the advantages of using it instead of char* / unsigned char* ? How to convert it to char* , and what differs when working with this type instead? 2. Question I've only seen char* when a string must

VHDL Bit Vector Operators

空扰寡人 提交于 2019-12-11 14:14:28
问题 I'm having a lot of trouble getting some simple math done in VHDL. I'm terrible at this language so if my syntax is stupid or something, I have an excuse :P. I'm trying to implement a very simple random number generator that calculates a pseudo-random number by this formula: seed = (seed*1103515245) + 12345 How I'm trying to do it: Signalss here signal seed: std_logic_vector(31 downto 0) := x"2B4C96B9"; signal multiply: std_logic_vector(31 downto 0) := x"41C64E6D"; signal add: std_logic

The “unsigned” keyword [duplicate]

北城以北 提交于 2019-12-11 10:33:54
问题 This question already has answers here : Difference between unsigned and unsigned int in C (5 answers) Closed 6 years ago . I saw in some C++ code the keyword "unsigned" in the following form: const int HASH_MASK = unsigned(-1) >> 1; and later: unsigned hash = HASH_SEED; (it is taken from the CS106B/X reader - of Stanford - by Eric S. Roberts - on the topic of "implementation of the hash code function for strings"). Can someone tell me please what does that keyword mean and when do I use it

How to use unsigned int to be able to use a function for JNA (Java Native Interface)?

天涯浪子 提交于 2019-12-11 09:59:42
问题 I'm using JNA in order to use a C++ library in my Java application. I am using an interface in Java to use these functions. The function uses three arguments in C++: an unsigned int, a const char*, and a long*. JNA implements Strings (according to their documents) in Java to pass in a char*. Likewise, it uses a long[] to pass in a long*. I'm confused, however, about the type that I should pass in for the unsigned int. The char* that is passed in represents the name of the file, and no matter

c语言类型浅谈

余生颓废 提交于 2019-12-11 08:30:00
C语言中的基本类型 //有符号类型 signed char; //1byte short; //2byte int; //4byte long int ; //4byte long long; //8byte //无符号类型 unsigned char; //1byte unsigned short; //2byte unsigned int; //4byte unsigned long int; //4byte unsigned long long; // 8byte //浮点型 float; //4byte double; //8byte long doube; //c11 12byte//c99 8byte //布尔型 //c语言中可能会用到#include<stdbool.h>头文件 bool; //1byte false true; //空类型 void; //不能定义变量,可以定义指针 # include <stdio.h> int main ( ) { printf ( "char型变量的大小为%d" , sizeof ( char ) ) ; printf ( "short型变量的大小为%d" , sizeof ( short ) ) ; printf ( "int型变量的大小为%d" , sizeof ( int ) ) ; printf ( "long

C/C++基本数据类型所占字节数

瘦欲@ 提交于 2019-12-11 05:32:11
1字节=8位 1k=1024字节=2^10 1m=1024k 1g=1024m 买硬盘实际内存小是因为厂商当1000换算的 这个基本的问题,很早以前就很清楚了,C标准中并没有具体给出规定那个基本类型应该是多少字节数,而且这个也与机器、OS、编译器有关,比如同样是在32bits的操作系统系,VC++的编译器下int类型为占4个字节;而tuborC下则是2个字节。 所以int,long int,short int的宽度都可能随编译器而异。但有几条铁定的原则(ANSI/ISO制订的): sizeof(short int)<=sizeof(int) sizeof(int)<=sizeof(long int) short int至少应为16位(2字节) long int至少应为32位。 下面给出不同位数编译器下的基本数据类型所占的字节数: 16位编译器 char :1个字节 char*(即指针变量): 2个字节 short int : 2个字节 int: 2个字节 unsigned int : 2个字节 float: 4个字节 double: 8个字节 long: 4个字节 long long: 8个字节 unsigned long: 4个字节 32位编译器 char :1个字节 char*(即指针变量): 4个字节(32位的寻址空间是2^32, 即32个bit,也就是4个字节

How to convert signed 16 bit integer to unsigned 16 bit integer in Java?

半城伤御伤魂 提交于 2019-12-11 04:19:38
问题 I have my below layout in which I need to represent my data and then finally I need to make one byte array out of that. I need to represent my data in the below format from Java code and then send the byte array to my C++ program which in turns c++ program unpacks the byte array and extract the relevant stuff from it - // below is my data layout - // // key type - 1 byte // key len - 1 byte // key (variable size = key_len) // timestamp (sizeof uint64_t) // data size (sizeof uint16_t), this is

value vs type: Code to Determine if a Variable Is Signed or Not

烂漫一生 提交于 2019-12-11 03:14:29
问题 I came across this question in a forum. The answer is something like this: #define ISUNSIGNED(a) (a >= 0 && ~a >= 0) //Alternatively, assuming the argument is to be a type, one answer would use type casts: #define ISUNSIGNED(type) ((type)0 - 1 > 0) I have a few questions regarding this.Why do we need to check ~a >= 0 ? What is the second solution all about? I did not understand the statement: "argument is to be a type". More importantly the author states that first #define will not work in

Implement `memcpy()`: Is `unsigned char *` needed, or just `char *`?

∥☆過路亽.° 提交于 2019-12-11 01:37:32
问题 I was implementing a version of memcpy() to be able to use it with volatile . Is it safe to use char * or do I need unsigned char * ? volatile void *memcpy_v(volatile void *dest, const volatile void *src, size_t n) { const volatile char *src_c = (const volatile char *)src; volatile char *dest_c = (volatile char *)dest; for (size_t i = 0; i < n; i++) { dest_c[i] = src_c[i]; } return dest; } I think unsigned should be necessary to avoid overflow problems if the data in any cell of the buffer is