Answered # hex-byte to short

_Nestor 12 Discussion Starter dav555 4 ArkM 1,090 Narue 5,707 Discussion Starter dav555 4 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

I don't know if there's a pre defined function but it shouldn't be too hard to code yourself.

Ignore the first two charactes and then convert from base sixteen to base 10.

You could use a for loop starting at the end of the string and multiply the number by 16 to the power of where it position is for example it would be 2 * 16 to the power of 0

0 * 16 to the power of one etc..

Obviously you will have to convert the character to an integer before doing the calculations

0

Ignore the first two charactes and then convert from base sixteen to base 10.

You could use a for loop starting at the end of the string and multiply the number by 16 to the power of where it position is for example it would be 2 * 16 to the power of 0

0 * 16 to the power of one etc..

Obviously you will have to convert the character to an integer before doing the calculations

i think you got me wrong. the hex value is not a c-string, its a "byte"-value. so there are not 4 characters but only one.

0

how can i convert a hex value of a byte (unsigned char) to a short value?

`unsigned char hexByte = 0x02; short value= ???`

thank you for your help!

As usually:

`short value = hexByte;`

What's a problem?

0

>how can i convert a hex value of a byte (unsigned char) to a short value?

By assigning it, perhaps? :icon_rolleyes:

```
unsigned char hexByte = 0x02;
short value = hexByte;
```

Your question betrays a misunderstanding of how numbers are represented in memory. There's no conversion going on[1]. The internal representation of hexByte is assigned to value, so it doesn't matter if you initialized it with a hexadecimal literal, an octal literal, or built it manually using bitwise operators in base 64. The result will remain the same.

[1] Unless you count the extension of the value from a smaller unsigned integer type to a larger signed integer type.

0

oh f***..i may have drunk too much yesterday...I thought it could be a problem because short has 2 Bytes and Char only 1...

thank you!

This question has already been answered. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...